perm filename TEXX.TEX[TEX,DEK] blob sn#841388 filedate 1987-06-14 generic text, type T, neo UTF8
\input webmac
% This program is copyright (C) 1982 by D. E. Knuth; all rights are reserved.
% Copying of this file is authorized only if (1) you are D. E. Knuth, or if
% (2) you make absolutely no changes to your copy. (The WEB system provides
% for alterations via an auxiliary file; the master file should stay intact.)
% See Appendix H of the WEB manual for hints on how to install this program.
% And see Appendix A of the TRIP manual for details about how to validate it.

% TeX is a trademark of the American Mathematical Society.
% METAFONT is a tradement of Addison-Wesley Publishing Company.

% Version 0 was released in September 1982 after it passed a variety of tests.
% Version 1 was released in November 1983 after thorough testing.
% Version 1.1 fixed ``disappearing font identifiers'' et alia (July 1984).
% Version 1.2 allows `0' in response to an error, et alia (October 1984).
% Version 1.3 made memory allocation more flexible and local (November 1984).
% Version 1.4 fixed accents right after line breaks, et alia (April 1985).
% Version 1.5 fixed \the\toks after other expansion in \edefs (August 1985).
% Version 2.0 (almost identical to 1.5) corresponds to "Volume B" (April 1986).
% Version 2.1 corrects anomalies in discretionary breaks (January 1987).
% Version 2.2 corrects "(Please type...)" with null \endlinechar (April 1987).

% A reward of $40.96 will be paid to the first finder of any remaining bug.
% (This amount will double again in 1988.)

% Although considerable effort has been expended to make the TeX program
% correct and reliable, no warranty is implied; the author disclaims any
% obligation or liability for damages, including but not limited to
% special, indirect, or consequential damages arising out of or in
% connection with the use or performance of this software. This work has
% been a ``labor of love'' and the author hopes that users enjoy it.

% Here is TeX material that gets inserted after \input webmac
\def\hang{\hangindent 3em\noindent\ignorespaces}
\def\textindent#1{\hangindent2.5em\noindent\hbox to2.5em{\hss#1 }\ignorespaces}
\font\ninerm=cmr9
\let\mc=\ninerm % medium caps for names like SAIL
\def\PASCAL{Pascal}
\def\ph{\hbox{Pascal-H}}
\font\logo=logo10 % font used for the METAFONT logo
\def\MF{{\logo META}\-{\logo FONT}}
\def\<#1>{$\langle#1\rangle$}
\def\section{\mathhexbox278}
\chardef\%=`\%

\def\(#1){} % this is used to make section names sort themselves better
\def\9#1{} % this is used for sort keys in the index via @:sort key}{entry@>

\def\drop{\kern-.1667em\lower.5ex\hbox{E}\kern-.125em} % middle of TeX
\catcode`E=13 \uppercase{\def E{e}}
\def\\#1{\hbox{\let E=\drop\it#1\/\kern.05em}} % italic type for identifiers

\outer\def\N#1. \[#2]#3.{\MN#1.\vfil\eject % begin starred section
  \def\rhead{PART #2:\uppercase{#3}} % define running headline
  \message{*\modno} % progress report
  \edef\next{\write\cont{\Z{\?#2]#3}{\modno}{\the\pageno}}}\next
  \ifon\startsection{\bf\ignorespaces#3.\quad}\ignorespaces}
\let\?=\relax % we want to be able to \write a \?

\def\title{\TeX82}
\def\topofcontents{\hsize 5.5in
	\vglue 0pt plus 1fil minus 1.5in
	\def\?##1]{\hbox{Changes to \hbox to 1em{\hfil##1}.\ }}
	}
\let\maybe=\iffalse
\def\botofcontents{\vskip 0pt plus 1fil minus 1.5in}
\pageno=3
\def\glob{13} % this should be the section number of "<Global...>"
\def\gglob{20, 26} % this should be the next two sections of "<Global...>"

\N1.  \[1] Introduction.
This is \TeX, a document compiler intended to produce high-quality typesetting.
The \PASCAL\ program that follows is the definition of \TeX82, a standard
version of \TeX\ that is designed to be highly portable so that identical
output
will be obtainable on a great variety of different computers.

The main purpose of the following program is to explain the algorithms of \TeX\
as clearly as possible. As a result, the program will not necessarily be very
efficient when a particular \PASCAL\ compiler has translated it into a
particular machine language. However, the program has been written so that it
can be tuned to run efficiently in a wide variety of operating environments
by making comparatively few changes. Such flexibility is possible because
the documentation that follows is written in the \.{WEB} language, which is
at a higher level than \PASCAL; the preprocessing step that converts \.{WEB}
to \PASCAL\ is able to introduce most of the necessary refinements.
Semi-automatic translation to other languages is also feasible, because the
program below does not make extensive use of features that are peculiar to
\PASCAL.

A large piece of software like \TeX\ has inherent complexity that cannot
be reduced below a certain level of difficulty, although each individual
part is fairly simple by itself. The \.{WEB} language is intended to make
the algorithms as readable as possible, by reflecting the way the
individual program pieces fit together and by providing the
cross-references that connect different parts. Detailed comments about
what is going on, and about why things were done in certain ways, have
been liberally sprinkled throughout the program.  These comments explain
features of the implementation, but they rarely attempt to explain the
\TeX\ language itself, since the reader is supposed to be familiar with
{\sl The \TeX book}.

\fi

\M2\*. The present implementation has a long ancestry, beginning in the summer
of~1977, when Michael~F. Plass and Frank~M. Liang designed and coded
a prototype
based on some specifications that the author had made in May of that year.
This original proto\TeX\ included macro definitions and elementary
manipulations on boxes and glue, but it did not have line-breaking,
page-breaking, mathematical formulas, alignment routines, error recovery,
or the present semantic nest; furthermore,
it used character lists instead of token lists, so that a control sequence
like \.{\\halign} was represented by a list of seven characters. A
complete version of \TeX\ was designed and coded by the author in late
1977 and early 1978; that program, like its prototype, was written in the
{\mc SAIL} language, for which an excellent debugging system was
available. Preliminary plans to convert the {\mc SAIL} code into a form
somewhat like the present ``web'' were developed by Luis Trabb~Pardo and
the author at the beginning of 1979, and a complete implementation was
created by Ignacio~A. Zabala in 1979 and 1980. The \TeX82 program, which
was written by the author during the latter part of 1981 and the early
part of 1982, also incorporates ideas from the 1979 implementation of
\TeX\ in {\mc MESA} that was written by Leonidas Guibas, Robert Sedgewick,
and Douglas Wyatt at the Xerox Palo Alto Research Center.  Several hundred
refinements were introduced into \TeX82 based on the experiences gained with
the original implementations, so that essentially every part of the system
has been substantially improved. After the appearance of ``Version 0'' in
September, 1982, this program benefited greatly from the comments of
many other people, notably David~R. Fuchs and Howard~W. Trickey.

No doubt there still is plenty of room for improvement, but the author
is firmly committed to keeping \TeX82 ``frozen'' from now on; stability
and reliability are to be its main virtues.

On the other hand, the \.{WEB} description can be extended without changing
the core of \TeX82 itself, and the program has been designed so that such
extensions are not extremely difficult to make.
The \\{banner} string defined here should be changed whenever \TeX\
undergoes any modifications, so that it will be clear which version of
\TeX\ might be the guilty party when a problem arises.

If this program is changed, the resulting system should not be called
`\TeX'; the official name `\TeX' by itself is reserved
for software systems that are fully compatible with each other.
A special test suite called the ``\.{TRIP} test'' is available for
helping to determine whether a particular implementation deserves to be
known as `\TeX' [cf.~Stanford Computer Science report CS1027,
November 1984].

\def\TeXX{\TeX\kern-.3emX}
Indeed, this program has been changed to allow extended characters,
so it is called `\TeXX'.

\Y\P\D \37$\\{banner}\S\.{\'This\ is\ TeXX,\ Version\ 2.2\'}$\C{printed when %
\TeX\ starts}\par
\fi

\M3. Different \PASCAL s have slightly different conventions, and the present
program expresses \TeX\ in terms of the \PASCAL\ that was
available to the author in 1982. The methods used here to work with
this particular compiler, which we shall call \ph, should help the
reader to see how to make an appropriate interface for other systems
if necessary. (\ph\ is Charles Hedrick's modification of a compiler
for the DECsystem-10 that was originally developed at the University of
Hamburg; cf.\ {\sl SOFTWARE---Practice \AM\ Experience \bf6} (1976),
29--42. The \TeX\ program below is intended to be adaptable, without
extensive changes, to most other versions of \PASCAL, so it does not fully
use the admirable features of \ph. Indeed, a conscious effort has been
made here to avoid using several idiosyncratic features of standard
\PASCAL\ itself, so that most of the code can be translated mechanically
into other high-level languages. For example, the `\&{with}' and `\\{new}'
features are not used, nor are pointer types, set types, or enumerated
scalar types; there are no `\&{var}' parameters, except in the case of files;
there are no tag fields on variant records; there are no assignments
$\\{real}\K\\{integer}$; no procedures are declared local to other procedures.)

The portions of this program that involve system-dependent code, where
changes might be necessary because of differences between \PASCAL\ compilers
and/or differences between
operating systems, can be identified by looking at the sections whose
numbers are listed under `system dependencies' in the index. Furthermore,
the index entries for `dirty \PASCAL' list all places where the restrictions
of \PASCAL\ have not been followed perfectly, for one reason or another.

\fi

\M4. The program begins with a normal \PASCAL\ program heading, whose
components will be filled in later, using the conventions of \.{WEB}.
For example, the portion of the program called `\X\glob:Global
variables\X' here will be replaced by a sequence of variable declarations
that starts in $\section\glob$ of this documentation. In this way, we are able
to define each individual global variable when we are prepared to
understand what it means; we do not have to define all of the globals at
once.  Cross references in $\section\glob$, where it says ``See also
sections \gglob, \dots,'' also make it possible to look at the set of
all global variables, if desired.  Similar remarks apply to the other
portions of the program heading.

Actually the heading shown here is not quite normal: The  \&{program}\   line
does not mention any \\{output} file, because \ph\ would ask the \TeX\ user
to specify a file name if \\{output} were specified here.

\Y\P\D \37$\\{mtype}\S\|t\J\|y\J\|p\J\|e$\C{this is a \.{WEB} coding trick:}\par
\P\F \37$\\{mtype}\S\\{type}$\C{`\&{mtype}' will be equivalent to `\&{type}'}%
\par
\P\F \37$\\{type}\S\\{true}$\C{but `\\{type}' will not be treated as a reserved
word}\par
\Y\P\hbox{\4}\X9\*:Compiler directives\X\6
\4\&{program}\1\  \37\\{TEX};\C{all file names are defined dynamically}\6
\4\&{label} \37\X6:Labels in the outer block\X\6
\4\&{const} \37\X11\*:Constants in the outer block\X\6
\4\&{mtype} \37\X18:Types in the outer block\X\6
\4\&{var} \37\X13:Global variables\X\7
\4\&{procedure}\1\  \37\\{initialize};\C{this procedure gets things started
properly}\6
\4\&{var} \37\X19:Local variables for initialization\X\2\6
\&{begin} \37\X8\*:Initialize whatever \TeX\ might access\X\6
\&{end};\7
\hbox{\4}\X57:Basic printing procedures\X\6
\hbox{\4}\X34\*:Error handling procedures\X\par
\fi

\M5. The overall \TeX\ program begins with the heading just shown, after which
comes a bunch of procedure declarations and function declarations.
Finally we will get to the main program, which begins with the
comment `\\{start\_here}'. If you want to skip down to the
main program now, you can look up `\\{start\_here}' in the index.
But the author suggests that the best way to understand this program
is to follow pretty much the order of \TeX's components as they appear in the
\.{WEB} description you are now reading, since the present ordering is
intended to combine the advantages of the ``bottom up'' and ``top down''
approaches to the problem of understanding a somewhat complicated system.

\fi

\M6. Three labels must be declared in the main program, so we give them
symbolic names.

\Y\P\D \37$\\{start\_of\_TEX}=1$\C{go here when \TeX's variables are
initialized}\par
\P\D \37$\\{end\_of\_TEX}=9998$\C{go here to close files and terminate
gracefully}\par
\P\D \37$\\{final\_end}=9999$\C{this label marks the ending of the program}\par
\Y\P$\4\X6:Labels in the outer block\X\S$\6
$\\{start\_of\_TEX}\hbox{\hskip-2pt},\39\\{end\_of\_TEX}\hbox{\hskip-2pt},\39\,%
\\{final\_end}$;\C{key control points}\par
\U section~4.\fi

\M7\*. Some of the code below is intended to be used only when diagnosing the
strange behavior that sometimes occurs when \TeX\ is being installed or
when system wizards are fooling around with \TeX\ without quite knowing
what they are doing. Such code will not normally be compiled; it is
delimited by the codewords `$ \&{debug} \ldots  \&{gubed} $', with apologies
to people who wish to preserve the purity of English.

Similarly, there is some conditional code delimited by
`$ \&{stat} \ldots  \&{tats} $' that is intended for use when statistics are to
be
kept about \TeX's memory usage.  The  \&{stat}  $\ldots$   \&{tats}  code also
implements diagnostic information for \\{tracing\_paragraphs} and
\\{tracing\_pages}.

\Y\P\D \37$\\{debug}\S$\C{change this to `$\\{debug}\equiv\null$' when
debugging}\par
\P\D \37$\\{gubed}\S$\C{change this to `$\\{gubed}\equiv\null$' when debugging}%
\par
\P\F \37$\\{debug}\S\\{begin}$\par
\P\F \37$\\{gubed}\S\\{end}$\Y\par
\P\D \37$\\{stat}\S$\C{change this to `$\\{stat}\equiv\.{@\{}$' when not
	gathering usage statistics}\par
\P\D \37$\\{tats}\S$\C{change this to `$\\{tats}\equiv\.{@\}}$' when not
	gathering usage statistics}\par
\P\F \37$\\{stat}\S\\{begin}$\par
\P\F \37$\\{tats}\S\\{end}$\par
\fi

\M8\*. This program has two important variations: (1) There is a long and slow
version called \.{INITEX}, which does the extra calculations needed to
initialize \TeX's internal tables; and (2)~there is a shorter and faster
production version, which cuts the initialization to a bare minimum.
Parts of the program that are needed in (1) but not in (2) are delimited by
the codewords `$ \&{init} \ldots  \&{tini} $'.

\Y\P\D \37$\\{init}\S$\C{change this to `$\\{init}\equiv\.{@\{}$' in the
production version}\par
\P\D \37$\\{tini}\S$\C{change this to `$\\{tini}\equiv\.{@\}}$' in the
production version}\par
\P\F \37$\\{init}\S\\{begin}$\par
\P\F \37$\\{tini}\S\\{end}$\par
\Y\P$\4\X8\*:Initialize whatever \TeX\ might access\X\S$\6
\X21:Set initial values of key variables\X\6
\&{init} \37\X164:Initialize table entries (done by \.{INITEX} only)\X\ %
\&{tini}\par
\U section~4.\fi

\M9\*. If the first character of a \PASCAL\ comment is a dollar sign,
\ph\ treats the comment as a list of ``compiler directives'' that will
affect the translation of this program into machine language.  The
directives shown below specify full checking and inclusion of the \PASCAL\
debugger when \TeX\ is being debugged, but they cause range checking and other
redundant code to be eliminated when the production system is being generated.
Arithmetic overflow will be detected in all cases.

\Y\P$\4\X9\*:Compiler directives\X\S$\6
$\B\J\$\|C-,\39\|A+,\39\|D-,\39\|W+\T$\C{no range check, catch arithmetic
overflow, no debug overhead}\6
\&{debug} \37$\B\J\$\|C+,\39\|D$: \37$5,\39\|W+,\39\|Z$: \37$\={377777777777B}%
\T$\ \&{gubed}\C{but turn everything on when debugging}\6
\C{the `$\|W+$' switch catches more syntax errors}\6
\C{the `\|Z' switch sets variables to maxint before they receive a value}\6
\C{the `\ignorespaces \|D: 5' avoids initial stop for the debugger}\par
\U section~4.\fi

\M10. This \TeX\ implementation conforms to the rules of the {\sl Pascal User
Manual} published by Jensen and Wirth in 1975, except where system-dependent
code is necessary to make a useful system program, and except in another
respect where such conformity would unnecessarily obscure the meaning
and clutter up the code: We assume that   \&{case}  statements may include a
default case that applies if no matching label is found. Thus, we shall use
constructions like
$$\vbox{\halign{\ignorespaces#\hfil\cr
 \&{case} $\|x$ \&{of}\cr
1: $\langle\,$code for $x=1\,\rangle$;\cr
3: $\langle\,$code for $x=3\,\rangle$;\cr
 \&{othercases}  $\langle\,$code for $\|x\I1$ and $\|x\I3$$\,\rangle$\cr
  \&{endcases} \cr}}$$
since most \PASCAL\ compilers have plugged this hole in the language by
incorporating some sort of default mechanism. For example, the \ph\
compiler allows `\\{others}:' as a default label, and other \PASCAL s allow
syntaxes like `\&{else}' or `\&{otherwise}' or `\\{otherwise}:', etc. The
definitions of  \&{othercases}  and   \&{endcases}  should be changed to agree
with
local conventions.  Note that no semicolon appears before   \&{endcases}  in
this program, so the definition of   \&{endcases}  should include a semicolon
if the compiler wants one. (Of course, if no default mechanism is
available, the   \&{case}  statements of \TeX\ will have to be laboriously
extended by listing all remaining cases. People who are stuck with such
\PASCAL s have in fact done this, successfully but not happily!)

\Y\P\D \37$\\{othercases}\S\\{others}$: \37\C{default for cases not listed
explicitly}\par
\P\D \37$\\{endcases}\S$\ \&{end} \C{follows the default case in an extended   %
\&{case}  statement}\par
\P\F \37$\\{othercases}\S\\{else}$\par
\P\F \37$\\{endcases}\S\\{end}$\par
\fi

\M11\*. The following parameters can be changed at compile time to extend or
reduce \TeX's capacity. They may have different values in \.{INITEX} and
in production versions of \TeX.

\Y\P$\4\X11\*:Constants in the outer block\X\S$\6
$\\{mem\_max}=3000$;\C{greatest index in \TeX's internal \\{mem} array; 	must
be strictly less than \\{max\_halfword}; 	must be equal to \\{mem\_top} in %
\.{INITEX}, otherwise $\G\\{mem\_top}$}\6
$\\{mem\_min}=1$;\C{smallest index in \TeX's internal \\{mem} array; 	must be %
\\{min\_halfword} or more; 	must be equal to \\{mem\_bot} in \.{INITEX},
otherwise $\L\\{mem\_bot}$}\6
$\\{buf\_size}=500$;\C{maximum number of characters simultaneously present in
	current lines of open files and in control sequences between 	\.{\\csname} and
\.{\\endcsname}; must not exceed \\{max\_halfword}}\6
$\\{error\_line}=64$;\C{width of context lines on terminal error messages}\6
$\\{half\_error\_line}=32$;\C{width of first lines of contexts in terminal
	error messages; should be between 30 and $\\{error\_line}-15$}\6
$\\{max\_print\_line}=72$;\C{width of longest text lines output; should be at
least 60}\6
$\\{stack\_size}=200$;\C{maximum number of simultaneous input sources}\6
$\\{max\_in\_open}=6$;\C{maximum number of input files and error insertions
that 	can be going on simultaneously}\6
$\\{font\_max}=75$;\C{maximum internal font number; must not exceed \\{max%
\_quarterword}}\6
$\\{font\_mem\_size}=20000$;\C{number of words of \\{font\_info} for all fonts}%
\6
$\\{param\_size}=60$;\C{maximum number of simultaneous macro parameters}\6
$\\{nest\_size}=40$;\C{maximum number of semantic levels simultaneously active}%
\6
$\\{max\_strings}=3000$;\C{maximum number of strings}\6
$\\{string\_vacancies}=8000$;\C{the minimum number of characters that should be
	available for the user's control sequences and font names, 	after \TeX's own
error messages are stored}\6
$\\{pool\_size}=32000$;\C{maximum number of characters in strings, including
all 	error messages and help texts, and the names of all fonts and 	control
sequences; must exceed \\{string\_vacancies} by the total 	length of \TeX's own
strings, which is currently about 22500}\6
$\\{save\_size}=600$;\C{space for saving values outside of current group; must
be 	at most \\{max\_halfword}}\6
$\\{trie\_size}=8000$;\C{space for hyphenation patterns; should be larger for 	%
\.{INITEX} than it is in production versions of \TeX}\6
$\\{dvi\_buf\_size}=800$;\C{size of the output buffer; must be a multiple of 8}%
\6
$\\{file\_name\_size}=23$;\C{file names shouldn't be longer than this}\6
$\\{pool\_name}=\.{\'TEX.POOL[TEX,DEK]\ \ \ \ \ \ \'}$;\C{string of length %
\\{file\_name\_size}; tells where the string pool appears}\par
\U section~4.\fi

\M12\*. Like the preceding parameters, the following quantities can be changed
at compile time to extend or reduce \TeX's capacity. But if they are changed,
it is necessary to rerun the initialization program \.{INITEX}
to generate new tables for the production \TeX\ program.
One can't simply make helter-skelter changes to the following constants,
since certain rather complex initialization
numbers are computed from them. They are defined here using
\.{WEB} macros, instead of being put into \PASCAL's  \&{const}  list, in order
to
emphasize this distinction.

\Y\P\D \37$\\{mem\_bot}=1$\C{smallest index in the \\{mem} array dumped by %
\.{INITEX}; 	must not be less than \\{mem\_min}}\par
\P\D \37$\\{mem\_top}\S3000$\C{largest index in the \\{mem} array dumped by %
\.{INITEX}; 	must be substantially larger than \\{mem\_bot} 	and not greater
than \\{mem\_max}}\par
\P\D \37$\\{font\_base}=0$\C{smallest internal font number; must not be less
	than \\{min\_quarterword}}\par
\P\D \37$\\{hash\_size}=2100$\C{maximum number of control sequences; it should
be at most 	about $(\\{mem\_max}-\\{hi\_mem\_base})/6$, but 2100 is already
quite generous}\par
\P\D \37$\\{hash\_prime}=1777$\C{a prime number equal to about 85\% of \\{hash%
\_size}}\par
\P\D \37$\\{hyph\_size}=307$\C{another prime; the number of \.{\\hyphenation}
exceptions}\par
\fi

\M13. In case somebody has inadvertently made bad settings of the
``constants,''
\TeX\ checks them using a global variable called \\{bad}.

This is the first of many sections of \TeX\ where global variables are
defined.

\Y\P$\4\X13:Global variables\X\S$\6
\4\\{bad}: \37\\{integer};\C{is some ``constant'' wrong?}\par
\A sections~20, 26, 30\*, 39, 50, 54, 73, 76, 79, 96, 104, 115, 116\*, 117,
118, 124, 165, 173, 181, 213, 246, 253, 256, 271, 286, 297, 301, 304\*, 305,
308, 309, 310, 333, 361, 382, 387, 388, 410, 438, 447, 480, 489, 493\*, 512,
513\*, 520\*, 527, 532, 539, 549, 550, 555, 592, 595\*, 605, 616, 646, 647,
661, 684, 719, 724, 764, 770, 814, 821, 823, 825, 828, 833, 839, 847, 872, 892,
900, 905, 921, 926, 943, 945, 946, 950, 971, 980, 982, 989, 1074, 1266, 1281,
1299, 1305, 1331, 1342, 1345, 1377\*, and~1379\*.
\U section~4.\fi

\M14. Later on we will say `\ignorespaces \&{if} $\\{mem\_max}\G\\{max%
\_halfword}$ \&{then} $\\{bad}\K14$',
or something similar. (We can't do that until \\{max\_halfword} has been
defined.)

\Y\P$\4\X14:Check the ``constant'' values for consistency\X\S$\6
$\\{bad}\K0$;\6
\&{if} $(\\{half\_error\_line}<30)\V(\\{half\_error\_line}>\\{error\_line}-15)$
\1\&{then}\5
$\\{bad}\K1$;\2\6
\&{if} $\\{max\_print\_line}<60$ \1\&{then}\5
$\\{bad}\K2$;\2\6
\&{if} $\\{dvi\_buf\_size}\mathbin{\&{mod}}8\I0$ \1\&{then}\5
$\\{bad}\K3$;\2\6
\&{if} $\\{mem\_bot}+1100>\\{mem\_top}$ \1\&{then}\5
$\\{bad}\K4$;\2\6
\&{if} $\\{hash\_prime}>\\{hash\_size}$ \1\&{then}\5
$\\{bad}\K5$;\2\6
\&{if} $\\{max\_in\_open}\G128$ \1\&{then}\5
$\\{bad}\K6$;\2\par
\A sections~111, 290, 522, and~1249.
\U section~1332.\fi

\M15. Labels are given symbolic names by the following definitions, so that
occasional \&{goto}  statements will be meaningful. We insert the label
`\\{exit}:' just before the `\ignorespaces  \&{end} \unskip' of a procedure in
which we have used the `\&{return}' statement defined below; the label
`\\{restart}' is occasionally used at the very beginning of a procedure; and
the label `\\{reswitch}' is occasionally used just prior to a   \&{case}
statement in which some cases change the conditions and we wish to branch
to the newly applicable case.  Loops that are set up with the  \~ \&{loop}
construction defined below are commonly exited by going to `\\{done}' or to
`\\{found}' or to `\\{not\_found}', and they are sometimes repeated by going to
`\\{continue}'.  If two or more parts of a subroutine start differently but
end up the same, the shared code may be gathered together at
`\\{common\_ending}'.

Incidentally, this program never declares a label that isn't actually used,
because some fussy \PASCAL\ compilers will complain about redundant labels.

\Y\P\D \37$\\{exit}=10$\C{go here to leave a procedure}\par
\P\D \37$\\{restart}=20$\C{go here to start a procedure again}\par
\P\D \37$\\{reswitch}=21$\C{go here to start a case statement again}\par
\P\D \37$\\{continue}=22$\C{go here to resume a loop}\par
\P\D \37$\\{done}=30$\C{go here to exit a loop}\par
\P\D \37$\\{done1}=31$\C{like \\{done}, when there is more than one loop}\par
\P\D \37$\\{done2}=32$\C{for exiting the second loop in a long block}\par
\P\D \37$\\{done3}=33$\C{for exiting the third loop in a very long block}\par
\P\D \37$\\{done4}=34$\C{for exiting the fourth loop in an extremely long
block}\par
\P\D \37$\\{done5}=35$\C{for exiting the fifth loop in an immense block}\par
\P\D \37$\\{done6}=36$\C{for exiting the sixth loop in a block}\par
\P\D \37$\\{found}=40$\C{go here when you've found it}\par
\P\D \37$\\{found1}=41$\C{like \\{found}, when there's more than one per
routine}\par
\P\D \37$\\{found2}=42$\C{like \\{found}, when there's more than two per
routine}\par
\P\D \37$\\{not\_found}=45$\C{go here when you've found nothing}\par
\P\D \37$\\{common\_ending}=50$\C{go here when you want to merge with another
branch}\par
\fi

\M16. Here are some macros for common programming idioms.

\Y\P\D \37$\\{incr}(\#)\S\#\K\#+1$\C{increase a variable by unity}\par
\P\D \37$\\{decr}(\#)\S\#\K\#-1$\C{decrease a variable by unity}\par
\P\D \37$\\{negate}(\#)\S\#\K-\#$\C{change the sign of a variable}\par
\P\D \37$\\{loop}\S$\ \&{while} $\\{true}$ \1\&{do}\ \C{repeat over and over
until a \&{goto}  happens}\par
\P\F \37$\\{loop}\S\\{xclause}$\C{\.{WEB}'s  \~ \&{xclause} acts like `%
\ignorespaces \&{while} $\\{true}$ \&{do}\unskip'}\par
\P\D \37$\\{do\_nothing}\S$\C{empty statement}\par
\P\D \37$\\{return}\S$\1\5
\&{goto} \37\\{exit}\C{terminate a procedure call}\2\par
\P\F \37$\\{return}\S\\{nil}$\par
\P\D \37$\\{empty}=0$\C{symbolic name for a null constant}\par
\fi

\N17.  \[2] The character set.
In order to make \TeX\ readily portable between a wide variety of
computers, all of its input text is converted to an internal seven-bit
code that is essentially standard ASCII, the ``American Standard Code for
Information Interchange.''  This conversion is done immediately when each
character is read in. Conversely, characters are converted from ASCII to
the user's external representation just before they are output to a
text file.

Such an internal code is relevant to users of \TeX\ primarily because it
governs the positions of characters in the fonts. For example, the
character `\.A' has ASCII code $65=\O{101}$, and when \TeX\ typesets
this letter it specifies character number 65 in the current font.
If that font actually has `\.A' in a different position, \TeX\ doesn't
know what the real position is; the program that does the actual printing from
\TeX's device-independent files is responsible for converting from ASCII to
a particular font encoding.

\TeX's internal code is relevant also with respect to constants
that begin with a reverse apostrophe; and it provides an index to the
\.{\\catcode}, \.{\\mathcode}, \.{\\uccode}, \.{\\lccode}, and \.{\\delcode}
tables.

\fi

\M18. Characters of text that have been converted to \TeX's internal form
are said to be of type \\{ASCII\_code}, which is a subrange of the integers.

\Y\P$\4\X18:Types in the outer block\X\S$\6
$\\{ASCII\_code}=0\to127$;\C{seven-bit numbers}\par
\A sections~25, 38, 101, 109, 113, 150, 212, 269, 300, 548, 594\*, 920, and~925.
\U section~4.\fi

\M19. The original \PASCAL\ compiler was designed in the late 60s, when six-bit
character sets were common, so it did not make provision for lowercase
letters. Nowadays, of course, we need to deal with both capital and small
letters in a convenient way, especially in a program for typesetting;
so the present specification of \TeX\ has been written under the assumption
that the \PASCAL\ compiler and run-time system permit the use of text files
with more than 64 distinguishable characters. More precisely, we assume that
the character set contains at least the letters and symbols associated
with ASCII codes \O{40} through \O{176}; all of these characters are now
available on most computer terminals.

Since we are dealing with more characters than were present in the first
\PASCAL\ compilers, we have to decide what to call the associated data
type. Some \PASCAL s use the original name \\{char} for the
characters in text files, even though there now are more than 64 such
characters, while other \PASCAL s consider \\{char} to be a 64-element
subrange of a larger data type that has some other name.

In order to accommodate this difference, we shall use the name \\{text\_char}
to stand for the data type of the characters that are converted to and
from \\{ASCII\_code} when they are input and output. We shall also assume
that \\{text\_char} consists of the elements $\\{chr}(\\{first\_text\_char})$
through
$\\{chr}(\\{last\_text\_char})$, inclusive. The following definitions should be
adjusted if necessary.

\Y\P\D \37$\\{text\_char}\S\\{char}$\C{the data type of characters in text
files}\par
\P\D \37$\\{first\_text\_char}=0$\C{ordinal number of the smallest element of %
\\{text\_char}}\par
\P\D \37$\\{last\_text\_char}=127$\C{ordinal number of the largest element of %
\\{text\_char}}\par
\Y\P$\4\X19:Local variables for initialization\X\S$\6
\4\|i: \37$0\to\\{last\_text\_char}$;\par
\A sections~163 and~927.
\U section~4.\fi

\M20. The \TeX\ processor converts between ASCII code and
the user's external character set by means of arrays \\{xord} and \\{xchr}
that are analogous to \PASCAL's \\{ord} and \\{chr} functions.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{xord}: \37\&{array} $[\\{text\_char}]$ \1\&{of}\5
\\{ASCII\_code};\C{specifies conversion of input characters}\2\6
\4\\{xchr}: \37\&{array} $[\\{ASCII\_code}]$ \1\&{of}\5
\\{text\_char};\C{specifies conversion of output characters}\2\par
\fi

\M21. Since we are assuming that our \PASCAL\ system is able to read and write
the
visible characters of standard ASCII (although not necessarily using the
ASCII codes to represent them), the following assignment statements initialize
most of the \\{xchr} array properly, without needing any system-dependent
changes. On the other hand, it is possible to implement \TeX\ with
less complete character sets, and in such cases it will be necessary to
change something here.

\Y\P$\4\X21:Set initial values of key variables\X\S$\6
$\\{xchr}[\O{40}]\K\.{\'\ \'}$;\5
$\\{xchr}[\O{41}]\K\.{\'!\'}$;\5
$\\{xchr}[\O{42}]\K\.{\'"\'}$;\5
$\\{xchr}[\O{43}]\K\.{\'\#\'}$;\5
$\\{xchr}[\O{44}]\K\.{\'\$\'}$;\5
$\\{xchr}[\O{45}]\K\.{\'\%\'}$;\5
$\\{xchr}[\O{46}]\K\.{\'\&\'}$;\5
$\\{xchr}[\O{47}]\K\.{\'\'}\.{\'\'}$;\6
$\\{xchr}[\O{50}]\K\.{\'(\'}$;\5
$\\{xchr}[\O{51}]\K\.{\')\'}$;\5
$\\{xchr}[\O{52}]\K\.{\'*\'}$;\5
$\\{xchr}[\O{53}]\K\.{\'+\'}$;\5
$\\{xchr}[\O{54}]\K\.{\',\'}$;\5
$\\{xchr}[\O{55}]\K\.{\'-\'}$;\5
$\\{xchr}[\O{56}]\K\.{\'.\'}$;\5
$\\{xchr}[\O{57}]\K\.{\'/\'}$;\6
$\\{xchr}[\O{60}]\K\.{\'0\'}$;\5
$\\{xchr}[\O{61}]\K\.{\'1\'}$;\5
$\\{xchr}[\O{62}]\K\.{\'2\'}$;\5
$\\{xchr}[\O{63}]\K\.{\'3\'}$;\5
$\\{xchr}[\O{64}]\K\.{\'4\'}$;\5
$\\{xchr}[\O{65}]\K\.{\'5\'}$;\5
$\\{xchr}[\O{66}]\K\.{\'6\'}$;\5
$\\{xchr}[\O{67}]\K\.{\'7\'}$;\6
$\\{xchr}[\O{70}]\K\.{\'8\'}$;\5
$\\{xchr}[\O{71}]\K\.{\'9\'}$;\5
$\\{xchr}[\O{72}]\K\.{\':\'}$;\5
$\\{xchr}[\O{73}]\K\.{\';\'}$;\5
$\\{xchr}[\O{74}]\K\.{\'<\'}$;\5
$\\{xchr}[\O{75}]\K\.{\'=\'}$;\5
$\\{xchr}[\O{76}]\K\.{\'>\'}$;\5
$\\{xchr}[\O{77}]\K\.{\'?\'}$;\6
$\\{xchr}[\O{100}]\K\.{\'@\'}$;\5
$\\{xchr}[\O{101}]\K\.{\'A\'}$;\5
$\\{xchr}[\O{102}]\K\.{\'B\'}$;\5
$\\{xchr}[\O{103}]\K\.{\'C\'}$;\5
$\\{xchr}[\O{104}]\K\.{\'D\'}$;\5
$\\{xchr}[\O{105}]\K\.{\'E\'}$;\5
$\\{xchr}[\O{106}]\K\.{\'F\'}$;\5
$\\{xchr}[\O{107}]\K\.{\'G\'}$;\6
$\\{xchr}[\O{110}]\K\.{\'H\'}$;\5
$\\{xchr}[\O{111}]\K\.{\'I\'}$;\5
$\\{xchr}[\O{112}]\K\.{\'J\'}$;\5
$\\{xchr}[\O{113}]\K\.{\'K\'}$;\5
$\\{xchr}[\O{114}]\K\.{\'L\'}$;\5
$\\{xchr}[\O{115}]\K\.{\'M\'}$;\5
$\\{xchr}[\O{116}]\K\.{\'N\'}$;\5
$\\{xchr}[\O{117}]\K\.{\'O\'}$;\6
$\\{xchr}[\O{120}]\K\.{\'P\'}$;\5
$\\{xchr}[\O{121}]\K\.{\'Q\'}$;\5
$\\{xchr}[\O{122}]\K\.{\'R\'}$;\5
$\\{xchr}[\O{123}]\K\.{\'S\'}$;\5
$\\{xchr}[\O{124}]\K\.{\'T\'}$;\5
$\\{xchr}[\O{125}]\K\.{\'U\'}$;\5
$\\{xchr}[\O{126}]\K\.{\'V\'}$;\5
$\\{xchr}[\O{127}]\K\.{\'W\'}$;\6
$\\{xchr}[\O{130}]\K\.{\'X\'}$;\5
$\\{xchr}[\O{131}]\K\.{\'Y\'}$;\5
$\\{xchr}[\O{132}]\K\.{\'Z\'}$;\5
$\\{xchr}[\O{133}]\K\.{\'[\'}$;\5
$\\{xchr}[\O{134}]\K\.{\'\\\'}$;\5
$\\{xchr}[\O{135}]\K\.{\']\'}$;\5
$\\{xchr}[\O{136}]\K\.{\'\↑\'}$;\5
$\\{xchr}[\O{137}]\K\.{\'\_\'}$;\6
$\\{xchr}[\O{140}]\K\.{\'\`\'}$;\5
$\\{xchr}[\O{141}]\K\.{\'a\'}$;\5
$\\{xchr}[\O{142}]\K\.{\'b\'}$;\5
$\\{xchr}[\O{143}]\K\.{\'c\'}$;\5
$\\{xchr}[\O{144}]\K\.{\'d\'}$;\5
$\\{xchr}[\O{145}]\K\.{\'e\'}$;\5
$\\{xchr}[\O{146}]\K\.{\'f\'}$;\5
$\\{xchr}[\O{147}]\K\.{\'g\'}$;\6
$\\{xchr}[\O{150}]\K\.{\'h\'}$;\5
$\\{xchr}[\O{151}]\K\.{\'i\'}$;\5
$\\{xchr}[\O{152}]\K\.{\'j\'}$;\5
$\\{xchr}[\O{153}]\K\.{\'k\'}$;\5
$\\{xchr}[\O{154}]\K\.{\'l\'}$;\5
$\\{xchr}[\O{155}]\K\.{\'m\'}$;\5
$\\{xchr}[\O{156}]\K\.{\'n\'}$;\5
$\\{xchr}[\O{157}]\K\.{\'o\'}$;\6
$\\{xchr}[\O{160}]\K\.{\'p\'}$;\5
$\\{xchr}[\O{161}]\K\.{\'q\'}$;\5
$\\{xchr}[\O{162}]\K\.{\'r\'}$;\5
$\\{xchr}[\O{163}]\K\.{\'s\'}$;\5
$\\{xchr}[\O{164}]\K\.{\'t\'}$;\5
$\\{xchr}[\O{165}]\K\.{\'u\'}$;\5
$\\{xchr}[\O{166}]\K\.{\'v\'}$;\5
$\\{xchr}[\O{167}]\K\.{\'w\'}$;\6
$\\{xchr}[\O{170}]\K\.{\'x\'}$;\5
$\\{xchr}[\O{171}]\K\.{\'y\'}$;\5
$\\{xchr}[\O{172}]\K\.{\'z\'}$;\5
$\\{xchr}[\O{173}]\K\.{\'\{\'}$;\5
$\\{xchr}[\O{174}]\K\.{\'|\'}$;\5
$\\{xchr}[\O{175}]\K\.{\'\}\'}$;\5
$\\{xchr}[\O{176}]\K\.{\'\~\'}$;\6
$\\{xchr}[0]\K\.{\'\ \'}$;\5
$\\{xchr}[\O{177}]\K\.{\'\ \'}$;\C{ASCII codes 0 and \O{177} do not appear in
text}\par
\A sections~23\*, 24, 74, 77, 80, 97, 166, 215, 254, 257, 272, 287, 383, 439,
481, 490, 521\*, 551, 556, 593, 596, 606, 648, 662, 685, 771, 928, 990, 1267,
1282, 1300, 1343, 1378\*, and~1380\*.
\U section~8\*.\fi

\M22. Some of the ASCII codes without visible characters have been given
symbolic
names in this program because they are used with a special meaning.

\Y\P\D \37$\\{null\_code}=\O{0}$\C{ASCII code that might disappear}\par
\P\D \37$\\{carriage\_return}=\O{15}$\C{ASCII code used at end of line}\par
\P\D \37$\\{invalid\_code}=\O{177}$\C{ASCII code that should not appear}\par
\fi

\M23\*. The ASCII code is ``standard'' only to a certain extent, since many
computer installations have found it advantageous to have ready access
to more than 94 printing characters. Appendix~C of {\sl The \TeX book\/}
gives a complete specification of the intended correspondence between
characters and \TeX's internal representation.

If \TeX\ is being used
on a garden-variety \PASCAL\ for which only standard ASCII
codes will appear in the input and output files, it doesn't really matter
what codes are specified in $\\{xchr}[1\to\O{37}]$, but the safest policy is to
blank everything out by using the code shown below.

However, other settings of \\{xchr} will make \TeX\ more friendly on
computers that have an extended character set, so that users can type things
like `\.↑↑Z' instead of `\.{\\ne}'. At MIT, for example, it would be more
appropriate to substitute the code
$$\hbox{ \&{for} $\|i\K1\mathrel{\&{to}}\O{37}$ \&{do} $\\{xchr}[\|i]\K\\{chr}(%
\|i)$;}$$
\TeX's character set is essentially the same as MIT's, even with respect to
characters less than~\O{40}. People with extended character sets can
assign codes arbitrarily, giving an \\{xchr} equivalent to whatever
characters the users of \TeX\ are allowed to have in their input files.
It is best to make the codes correspond to the intended interpretations as
shown in Appendix~C whenever possible; but this is not necessary. For
example, in countries with an alphabet of more than 26 letters, it is
usually best to map the additional letters into codes less than~\O{40}.

The code shown here is intended to be used on the Stanford {\sc SAIL} system,
and at other installations like CMU and ISI where essentially the same
extended character set is used. The fact that {\mc SAIL} has \.{\'\}\'} in the
wrong place turns out to cause no difficulty in this case.

\Y\P$\4\X21:Set initial values of key variables\X\mathrel{+}\S$\6
\&{for} $\|i\K1\mathrel{\&{to}}\O{37}$ \1\&{do}\5
$\\{xchr}[\|i]\K\\{chr}(\|i)$;\2\6
$\\{xchr}[\O{30}]\K\\{chr}(\O{137})$;\5
$\\{xchr}[\O{32}]\K\\{chr}(\O{33})$;\C{\\{not\_equal} sign}\6
$\\{xchr}[\O{33}]\K\\{chr}(\O{176})$;\par
\fi

\M24. The following system-independent code makes the \\{xord} array contain a
suitable inverse to the information in \\{xchr}. Note that if $\\{xchr}[\|i]=%
\\{xchr}[\|j]$
where $\|i<\|j<\O{177}$, the value of $\\{xord}[\\{xchr}[\|i]]$ will turn out
to be
\|j or more; hence, standard ASCII code numbers will be used instead of
codes below \O{40} in case there is a coincidence.

\Y\P$\4\X21:Set initial values of key variables\X\mathrel{+}\S$\6
\&{for} $\|i\K\\{first\_text\_char}\mathrel{\&{to}}\\{last\_text\_char}$ \1%
\&{do}\5
$\\{xord}[\\{chr}(\|i)]\K\\{invalid\_code}$;\2\6
\&{for} $\|i\K1\mathrel{\&{to}}\O{176}$ \1\&{do}\5
$\\{xord}[\\{xchr}[\|i]]\K\|i$;\2\par
\fi

\N25.  \[3] Input and output.
The bane of portability is the fact that different operating systems treat
input and output quite differently, perhaps because computer scientists
have not given sufficient attention to this problem. People have felt somehow
that input and output are not a part of ``real'' programming. Well, it is true
that some kinds of programming are more fun than others. With existing
input/output conventions being so diverse and so messy, the only sources of
joy in such parts of the code are the rare occasions when one can find a
way to make the program a little less bad than it might have been. We have
two choices: either to attack I/O now and get it over with, or to postpone
it until near the end. Neither prospect is very attractive, so let's
get it over with.

The basic operations we need to do are (1)~inputting and outputting of
text, to or from a file or the user's terminal; (2)~inputting and
outputting of eight-bit bytes, to or from a file; (3)~instructing the
operating system to initiate (``open'') or to terminate (``close'') input or
output from a specified file; (4)~testing whether the end of an input
file has been reached.

\TeX\ needs to deal with two kinds of files.
We shall use the term \\{alpha\_file} for a file that contains textual data,
and the term \\{byte\_file} for a file that contains eight-bit binary
information.
These two types turn out to be the same on many computers, but
sometimes there is a significant distinction, so we shall be careful to
distinguish between them. Standard protocols for transferring
such files from computer to computer, via high-speed networks, are
now becoming available to more and more communities of users.

The program actually makes use also of a third kind of file, called a
\\{word\_file}, when dumping and reloading base information for its own
initialization.  We shall define a word file later; but it will be possible
for us to specify simple operations on word files before they are defined.

\Y\P$\4\X18:Types in the outer block\X\mathrel{+}\S$\6
$\\{eight\_bits}=0\to255$;\C{unsigned one-byte quantity}\6
$\\{alpha\_file}=$\1\5
\&{packed} \37\&{file} \1\&{of}\5
\\{text\_char};\C{files that contain textual data}\2\2\6
$\\{byte\_file}=$\1\5
\&{packed} \37\&{file} \1\&{of}\5
\\{eight\_bits};\C{files that contain binary data}\2\2\par
\fi

\M26. Most of what we need to do with respect to input and output can be
handled
by the I/O facilities that are standard in \PASCAL, i.e., the routines
called \\{get}, \\{put}, \\{eof}, and so on. But
standard \PASCAL\ does not allow file variables to be associated with file
names that are determined at run time, so it cannot be used to implement
\TeX; some sort of extension to \PASCAL's ordinary \\{reset} and \\{rewrite}
is crucial for our purposes. We shall assume that \\{name\_of\_file} is a
variable
of an appropriate type such that the \PASCAL\ run-time system being used to
implement \TeX\ can open a file whose external name is specified by
\\{name\_of\_file}.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{name\_of\_file}: \37\&{packed} \37\&{array} $[1\to\\{file\_name\_size}]$ %
\1\&{of}\5
\\{char};\2\6
\C{on some systems this may be a \&{record} variable}\6
\4\\{name\_length}: \37$0\to\\{file\_name\_size}$;\6
\C{this many characters are actually 	relevant in \\{name\_of\_file} (the rest
are blank)}\par
\fi

\M27\*. The \ph\ compiler with which the present version of \TeX\ was prepared
has
extended the rules of \PASCAL\ in a very convenient way. To open file~\|f,
we can write
$$\vbox{\halign{#\hfil\qquad&#\hfil\cr
$\\{reset}(\|f,\hbox{\\{name}},\.{\'/O\'})$&for input;\cr
$\\{rewrite}(\|f,\hbox{\\{name}},\.{\'/O\'})$&for output.\cr}}$$
The `\\{name}' parameter, which is of type `{\bf packed array
$[\langle\\{any}\rangle]$ of \\{char}}', stands for the name of
the external file that is being opened for input or output.
Blank spaces that might appear in \\{name} are ignored.

The `\.{/O}' parameter tells the operating system not to issue its own
error messages if something goes wrong. If a file of the specified name
cannot be found, or if such a file cannot be opened for some other reason
(e.g., someone may already be trying to write the same file), we will have
$\\{erstat}(\|f)\I0$ after an unsuccessful \\{reset} or \\{rewrite}.  This
allows
\TeX\ to undertake appropriate corrective action.

\TeX's file-opening procedures return \\{false} if no file identified by
\\{name\_of\_file} could be opened.

\Y\P\D \37$\\{reset\_OK}(\#)\S\\{erstat}(\#)\mathbin{\&{mod}}\O{20000}=0$\par
\P\D \37$\\{rewrite\_OK}(\#)\S\\{erstat}(\#)\mathbin{\&{mod}}\O{20000}=0$\par
\Y\P\4\&{function} \1\  \\{erstat} ( $\mathop{\&{var}}\|f:$ \&{file} ) : %
\\{integer};\5
\\{extern};\5
\hbox{/2}\7
\4\&{function}\1\  \37$\\{a\_open\_in}(\mathop{\&{var}}\|f:\\{alpha\_file})$: %
\37\\{boolean};\C{open a text file for input}\2\6
\&{begin} \37$\\{reset}(\|f,\39\\{name\_of\_file},\39\.{\'/E/O/N:9\'})$;\C{the %
\.{/E} switch distinguishes \\{form\_feed} from \\{carriage\_return}; 	the %
\.{/O} switch gives error control to us; 	and the \.{/N:9} switch specifies 9
buffers, which 	seems to work satisfactorily at {\mc SAIL}}\6
$\\{a\_open\_in}\K\\{reset\_OK}(\|f)$;\6
\&{end};\7
\4\&{function}\1\  \37$\\{a\_open\_out}(\mathop{\&{var}}\|f:\\{alpha\_file})$: %
\37\\{boolean};\C{open a text file for output}\2\6
\&{begin} \37$\\{rewrite}(\|f,\39\\{name\_of\_file},\39\.{\'/O/N:2\'})$;\5
$\\{a\_open\_out}\K\\{rewrite\_OK}(\|f)$;\6
\&{end};\C{two buffers seems adequate for text output files}\7
\4\&{function}\1\  \37$\\{b\_open\_in}(\mathop{\&{var}}\|f:\\{byte\_file})$: %
\37\\{boolean};\C{open a binary file for input}\2\6
\&{begin} \37$\\{reset}(\|f,\39\\{name\_of\_file},\39\.{\'/B:8/O/N:2\'})$;\5
$\\{b\_open\_in}\K\\{reset\_OK}(\|f)$;\6
\&{end};\C{the \.{/B} switch is necessary to get byte packing}\7
\4\&{function}\1\  \37$\\{b\_open\_out}(\mathop{\&{var}}\|f:\\{byte\_file})$: %
\37\\{boolean};\C{open a binary file for output}\2\6
\&{begin} \37$\\{rewrite}(\|f,\39\\{name\_of\_file},\39\.{\'/O/N:9/P:256\'})$;\5
$\\{b\_open\_out}\K\\{rewrite\_OK}(\|f)$;\6
\&{end};\C{here we use \\{ary\_out} so the \.{/B} switch isn't appropriate}\6
\C{the \.{/P:256} sets file protection to `dump never'}\7
\4\&{function}\1\  \37$\\{w\_open\_in}(\mathop{\&{var}}\|f:\\{word\_file})$: %
\37\\{boolean};\C{open a word file for input}\2\6
\&{begin} \37$\\{reset}(\|f,\39\\{name\_of\_file},\39\.{\'/O/N:9\'})$;\5
$\\{w\_open\_in}\K\\{reset\_OK}(\|f)$;\6
\&{end};\7
\4\&{function}\1\  \37$\\{w\_open\_out}(\mathop{\&{var}}\|f:\\{word\_file})$: %
\37\\{boolean};\C{open a word file for output}\2\6
\&{begin} \37$\\{rewrite}(\|f,\39\\{name\_of\_file},\39\.{\'/O/N:9\'})$;\5
$\\{w\_open\_out}\K\\{rewrite\_OK}(\|f)$;\6
\&{end};\par
\fi

\M28. Files can be closed with the \ph\ routine `$\\{close}(\|f)$', which
should be used when all input or output with respect to \|f has been completed.
This makes \|f available to be opened again, if desired; and if \|f was used
for
output, the \\{close} operation makes the corresponding external file appear
on the user's area, ready to be read.

These procedures should not generate error messages if a file is
being closed before it has been successfully opened.

\Y\P\4\&{procedure}\1\  \37$\\{a\_close}(\mathop{\&{var}}\|f:\\{alpha\_file})$;%
\C{close a text file}\2\6
\&{begin} \37$\\{close}(\|f)$;\6
\&{end};\7
\4\&{procedure}\1\  \37$\\{b\_close}(\mathop{\&{var}}\|f:\\{byte\_file})$;%
\C{close a binary file}\2\6
\&{begin} \37$\\{close}(\|f)$;\6
\&{end};\7
\4\&{procedure}\1\  \37$\\{w\_close}(\mathop{\&{var}}\|f:\\{word\_file})$;%
\C{close a word file}\2\6
\&{begin} \37$\\{close}(\|f)$;\6
\&{end};\par
\fi

\M29. Binary input and output are done with \PASCAL's ordinary \\{get} and %
\\{put}
procedures, so we don't have to make any other special arrangements for
binary~I/O. Text output is also easy to do with standard \PASCAL\ routines.
The treatment of text input is more difficult, however, because
of the necessary translation to \\{ASCII\_code} values, and because
\TeX's conventions should be efficient and they should
blend nicely with the user's operating environment.

\fi

\M30\*. Input from text files is read one line at a time, using a routine
called
\\{input\_ln}. This function is defined in terms of global variables
called \\{buffer}, \\{first}, and \\{last} that will be described in detail
later; for now, it suffices for us to know that \\{buffer} is an array of
\\{ASCII\_code} values, and that \\{first} and \\{last} are indices into this
array representing the beginning and ending of a line of text.

We will read the lines first into an auxiliary buffer, in order to
save the running time of procedure-call overhead. This uses a nice
feature of \ph\ that Knuth chose not to mention in \TeX82.

At {\mc SAIL} we want to recognize page marks (indicated by \\{form\_feed}
characters), and keep track of the current page number.

\Y\P\D \37$\\{form\_feed}=\O{14}$\C{ASCII code used at end of a page}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{buffer}: \37\&{array} $[0\to\\{buf\_size}]$ \1\&{of}\5
\\{ASCII\_code};\C{lines of characters being read}\2\6
\4\\{first}: \37$0\to\\{buf\_size}$;\C{the first unused position in \\{buffer}}%
\6
\4\\{last}: \37$0\to\\{buf\_size}$;\C{end of the line just input to \\{buffer}}%
\6
\4\\{max\_buf\_stack}: \37$0\to\\{buf\_size}$;\C{largest index used in %
\\{buffer}}\6
\4\\{aux\_buf}: \37\&{array} $[0\to70]$ \1\&{of}\5
\\{text\_char};\C{where the characters go first}\2\par
\fi

\M31\*. The \\{input\_ln} function brings the next line of input from the
specified
file into available positions of the buffer array and returns the value
\\{true}, unless the file has already been entirely read, in which case it
returns \\{false} and sets $\\{last}\K\\{first}$.  In general, the \\{ASCII%
\_code}
numbers that represent the next line of the file are input into
$\\{buffer}[\\{first}]$, $\\{buffer}[\\{first}+1]$, \dots, $\\{buffer}[%
\\{last}-1]$; and the
global variable \\{last} is set equal to \\{first} plus the length of the
line. Trailing blanks are removed from the line; thus, either $\\{last}=%
\\{first}$
(in which case the line was entirely blank) or $\\{buffer}[\\{last}-1]\I\.{"\
"}$.

An overflow error is given, however, if the normal actions of \\{input\_ln}
would make $\\{last}\G\\{buf\_size}$; this is done so that other parts of \TeX\
can safely look at the contents of $\\{buffer}[\\{last}+1]$ without
overstepping
the bounds of the \\{buffer} array. Upon entry to \\{input\_ln}, the condition
$\\{first}<\\{buf\_size}$ will always hold, so that there is always room for an
``empty'' line.

The variable \\{max\_buf\_stack}, which is used to keep track of how large
the \\{buf\_size} parameter must be to accommodate the present job, is
also kept up to date by \\{input\_ln}.

If the \\{bypass\_eoln} parameter is \\{true}, \\{input\_ln} will do a \\{get}
before looking at the first character of the line; this skips over
an \\{eoln} that was in $\|f\↑$. The procedure does not do a \\{get} when it
reaches the end of the line; therefore it can be used to acquire input
from the user's terminal as well as from ordinary text files.

Standard \PASCAL\ says that a file should have \\{eoln} immediately
before \\{eof}, but \TeX\ needs only a weaker restriction: If \\{eof}
occurs in the middle of a line, the system function \\{eoln} should return
a \\{true} result (even though $\|f\↑$ will be undefined).

Since the inner loop of \\{input\_ln} is part of \TeX's ``inner loop''---each
character of input comes in at this place---it is wise to reduce system
overhead by making use of special routines that read in an entire array
of characters at once, if such routines are available. The following
code uses standard \PASCAL\ to illustrate what needs to be done, but
finer tuning is often possible at well-developed \PASCAL\ sites.

\Y\P\4\&{function}\1\  \37$\\{input\_ln}(\mathop{\&{var}}\|f:\\{alpha\_file};\,%
\35\\{bypass\_eoln}:\\{boolean})$: \37\\{boolean};\C{inputs the next line or
returns \\{false}}\6
\4\&{label} \37$1,\39\\{done}$;\6
\4\&{var} \37\|n: \37\\{integer};\5
$\|k,\39\|m$: \37$0\to\\{buf\_size}$;\C{indices into \\{buffer}}\2\6
\&{begin} \37\&{if} $\\{bypass\_eoln}$ \1\&{then}\C{input the first character
of the line into $\|f\↑$}\6
\&{begin} \37\&{if} $\R\\{eof}(\|f)$ \1\&{then}\5
$\\{get}(\|f)$;\2\6
\&{if} $\R\\{eof}(\|f)$ \1\&{then}\6
\&{if} $\|f\↑=\\{chr}(\O{12})$ \1\&{then}\5
$\\{get}(\|f)$;\C{skip past a \\{line\_feed}}\2\2\6
\&{end};\2\6
$\\{last}\K\\{first}$;\6
\&{if} $\\{eof}(\|f)$ \1\&{then}\5
$\\{input\_ln}\K\\{false}$\6
\4\&{else} \&{begin} \37$\\{read}(\|f,\39\\{aux\_buf}:\|n)$;\6
\&{if} $\\{buffer}[\\{first}]=\\{form\_feed}$ \1\&{then}\C{previous line was
end-of-page}\6
\&{begin} \37$\\{incr}(\\{page})$;\5
$\\{line}\K1$;\C{adjust line and page numbers}\6
\&{end};\2\6
\41: \37\&{if} $\\{last}+\|n>\\{max\_buf\_stack}$ \1\&{then}\6
\&{if} $\\{last}+\|n\G\\{buf\_size}$ \1\&{then}\6
\&{begin} \37$\\{max\_buf\_stack}\K\\{buf\_size}$;\5
$\\{overflow}(\.{"buffer\ size"},\39\\{buf\_size})$;\6
\&{end}\6
\4\&{else} $\\{max\_buf\_stack}\K\\{last}+\|n$;\2\2\6
\&{if} $\|n>0$ \1\&{then}\6
\&{begin} \37$\|m\K\\{last}$;\6
\&{if} $\|n=72$ \1\&{then}\5
$\\{last}\K\|m+71$\ \&{else} $\\{last}\K\|m+\|n$;\2\6
\&{for} $\|k\K\|m\mathrel{\&{to}}\\{last}-1$ \1\&{do}\5
$\\{buffer}[\|k]\K\\{xord}[\\{aux\_buf}[\|k-\|m]]$;\2\6
\&{if} $\|n=72$ \1\&{then}\C{there's more on this line}\6
\&{begin} \37$\\{read}(\|f,\39\\{aux\_buf}:\|n)$;\5
\&{goto} \371;\6
\&{end};\2\6
\&{end}\6
\4\&{else} \&{if} $\|f\↑=\\{chr}(\\{form\_feed})$ \1\&{then}\C{end of page}\6
\&{begin} \37$\\{aux\_buf}[0]\K\|f\↑$;\5
$\|n\K1$;\5
\&{goto} \371;\6
\&{end};\2\2\6
\~ \1\&{loop}\ \&{begin} \37\&{if} $\\{last}=\\{first}$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
\&{if} $\\{buffer}[\\{last}-1]\I\.{"\ "}$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
$\\{decr}(\\{last})$;\6
\&{end};\2\6
\4\\{done}: \37$\\{input\_ln}\K\\{true}$;\6
\&{end};\2\6
\&{end};\par
\fi

\M32\*. The user's terminal acts essentially like other files of text, except
that it is used both for input and for output. When the terminal is
considered an input file, the file variable is called \\{term\_in}, and when it
is considered an output file the file variable is \\{term\_out}.
On WAITS, this point is moot, since we use the built-in \\{TTY} file.

\Y\P\D \37$\\{term\_in}\S\\{TTY}$\C{the terminal as an input file}\par
\P\D \37$\\{term\_out}\S\\{TTY}$\C{the terminal as an output file}\par
\fi

\M33\*. Here is how to open the terminal files on WAITS: we don't do anything,
since \\{TTY} is always open.  Note that $\\{eoln}(\\{term\_in})$ is initially %
\\{true}.

\Y\P\D \37$\\{t\_open\_in}\S\\{do\_nothing}$\C{open the terminal for text
input}\par
\P\D \37$\\{t\_open\_out}\S\\{do\_nothing}$\C{open the terminal for text
output}\par
\fi

\M34\*. Sometimes it is necessary to synchronize the input/output mixture that
happens on the user's terminal, and three procedures are used for this
purpose. The first of these, \\{update\_terminal}, is called when we want
to make sure that everything we have output to the terminal so far has
actually left the computer's internal buffers and been sent.
The second, \\{clear\_terminal}, is called when we wish to cancel any
input that the user may have typed ahead (since we are about to
issue an unexpected error message). The third, \\{wake\_up\_terminal},
is supposed to revive the terminal if the user has disabled it by
some instruction to the operating system.  The following macros show how
these operations can be specified in \ph:

\Y\P\D \37$\\{update\_terminal}\S\\{break}(\\{term\_out})$\C{empty the terminal
output buffer}\par
\P\D \37$\\{clear\_terminal}\S\\{break\_in}(\\{term\_in},\39\\{true})$\C{clear
the terminal input buffer}\par
\P\D \37$\\{wake\_up\_terminal}\S$\1\6
\&{begin} \37\&{if} $\\{inskp0}$ \1\&{then}\2\6
\&{end}\C{cancel the user's cancellation of output}\2\par
\Y\P$\4\X34\*:Error handling procedures\X\S$\6
\4\&{function}\1\  \37\\{inskp0}: \37\\{boolean};\5
\\{extern};\par
\A sections~78, 81, 82, 93, 94, and~95.
\U section~4.\fi

\M35. We need a special routine to read the first line of \TeX\ input from
the user's terminal. This line is different because it is read before we
have opened the transcript file; there is sort of a ``chicken and
egg'' problem here. If the user types `\.{\\input paper}' on the first
line, or if some macro invoked by that line does such an \.{\\input},
the transcript file will be named `\.{paper.log}'; but if no \.{\\input}
commands are performed during the first line of terminal input, the transcript
file will acquire its default name `\.{texput.log}'. (The transcript file
will not contain error messages generated by the first line before the
first \.{\\input} command.)

The first line is even more special if we are lucky enough to have an operating
system that treats \TeX\ differently from a run-of-the-mill \PASCAL\ object
program. It's nice to let the user start running a \TeX\ job by typing
a command line like `\.{tex paper}'; in such a case, \TeX\ will operate
as if the first line of input were `\.{paper}', i.e., the first line will
consist of the remainder of the command line, after the part that invoked
\TeX.

\fi

\M36. Different systems have different ways to get started. But regardless of
what conventions are adopted, the routine that initializes the terminal
should satisfy the following specifications:

\yskip\textindent{1)}It should open file \\{term\_in} for input from the
terminal. (The file \\{term\_out} will already be open for output to the
terminal.)

\textindent{2)}If the user has given a command line, this line should be
considered the first line of terminal input. Otherwise the
user should be prompted with `\.{**}', and the first line of input
should be whatever is typed in response.

\textindent{3)}The first line of input, which might or might not be a
command line, should appear in locations \\{first} to $\\{last}-1$ of the
\\{buffer} array.

\textindent{4)}The global variable \\{loc} should be set so that the
character that \TeX\ reads next is in $\\{buffer}[\\{loc}]$. This
character should not be blank, and we should have $\\{loc}<\\{last}$.

\yskip\noindent(It may be necessary to prompt the user several times
before a non-blank line comes in. The prompt is `\.{**}' instead of the
later `\.*' because the meaning is slightly different: `\.{\\input}' need
not be typed immediately after~`\.{**}'.)

\Y\P\D \37$\\{loc}\S\\{cur\_input}.\\{loc\_field}$\C{location of first unread
character in \\{buffer}}\par
\fi

\M37\*. The following program does the required initialization
and accepts interrupts and also retrieves a possible command line, using
new system routines due to David R. Fuchs.

\Y\P\D \37$\\{pto\_chr}(\#)\S\\{ptwr1w}(0,\39\\{ord}(\#))$\C{put a character in
the line editor}\par
\Y\P\4\&{procedure}\1\  \37$\\{esci}(\mathop{\&{var}}\|x:\\{integer})$;\5
\\{extern};\5
\hbox{\2}\C{increments \|x each time the user types escape-I or break-I; 	the
program can change \|x whenever it wants to, but \|x had 	better be a global
variable}\7
\4\&{function}\1\  \37\\{rescan}: \37\\{boolean};\5
\\{extern};\5
\hbox{\2}\C{puts the command line into the terminal buffer, 	or returns %
\\{false} if there was no command line}\7
\4\&{function}\1\  \37$\\{tmp\_in}(\|f:\\{string};\,\35\mathop{\&{var}}\|s:%
\\{string})$: \37\\{integer};\5
\\{extern};\5
\hbox{\2}\C{reads \.{TMPCOR} file \|f into \|s, and returns its length 		($\L0$
means error)}\7
\4\&{function}\1\  \37\\{cclsw}: \37\\{boolean};\5
\\{extern};\5
\hbox{\2}\C{was program started with \.{RUN} offset of 1 (i.e., from %
\.{SNAIL})?}\7
\4\&{procedure}\1\  \37$\\{ptwr1w}(\\{pty},\39\|c:\\{integer})$;\5
\\{extern};\5
\hbox{\2}\C{simulates typing of a character on a \.{PTY}}\7
\4\&{function}\1\  \37\\{init\_terminal}: \37\\{boolean};\C{gets the terminal
files started}\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37\|l: \37\\{integer};\C{length returned by \\{tmp\_in}}\6
\\{line\_found}: \37\\{boolean};\C{have we scanned a line?}\6
\\{tmp\_cor\_buf}: \37\&{packed} \37\&{array} $[0\to100]$ \1\&{of}\5
\\{char};\C{where \\{tmp\_in} puts things}\2\2\6
\&{begin} \37\\{t\_open\_in};\5
$\\{esci}(\\{interrupt})$;\5
$\\{last}\K\\{first}$;\6
\&{if} $\\{cclsw}$ \1\&{then}\C{started by \.{TEX} monitor command}\6
\&{begin} \37$\|l\K\\{tmp\_in}(\.{\'TEX\'},\39\\{tmp\_cor\_buf})$;\5
$\\{loc}\K1$;\6
\&{while} $(\\{loc}<\|l)\W(\\{tmp\_cor\_buf}[\\{loc}]\I\.{\'←\'})$ \1\&{do}\5
$\\{incr}(\\{loc})$;\2\6
$\\{incr}(\\{loc})$;\6
\&{while} $\\{loc}<\|l$ \1\&{do}\6
\&{begin} \37\&{if} $\\{tmp\_cor\_buf}[\\{loc}]>\.{\'\ \'}$ \1\&{then}\6
\&{begin} \37$\\{buffer}[\\{last}]\K\\{xord}[\\{tmp\_cor\_buf}[\\{loc}]]$;\5
$\\{incr}(\\{last})$;\6
\&{end};\2\6
$\\{incr}(\\{loc})$;\6
\&{end};\2\6
\&{end}\6
\4\&{else} \&{debug} \37\&{if} $\\{false}$ \1\&{then}\ \2\6
\&{gubed}\2\6
\&{if} $\\{rescan}$ \1\&{then}\6
\&{begin} \37$\\{read\_ln}(\\{term\_in})$;\C{get first character into $\\{term%
\_in}\↑$}\6
\&{while} $(\R\\{eoln}(\\{term\_in}))\W(\\{term\_in}\↑\I\.{\';\'})$ \1\&{do}\5
$\\{get}(\\{term\_in})$;\2\6
\&{if} $\\{term\_in}\↑=\.{\';\'}$ \1\&{then}\6
\&{begin} \37$\\{get}(\\{term\_in})$;\6
\&{while} $\R\\{eoln}(\\{term\_in})$ \1\&{do}\6
\&{begin} \37$\\{buffer}[\\{last}]\K\\{xord}[\\{term\_in}\↑]$;\5
$\\{incr}(\\{last})$;\5
$\\{get}(\\{term\_in})$;\6
\&{end};\2\6
\&{end};\2\6
\&{end};\2\6
$\\{line\_found}\K(\\{last}>\\{first})$;\6
\~ \1\&{loop}\ \&{begin} \37$\\{loc}\K\\{first}$;\6
\&{while} $(\\{loc}<\\{last})\W(\\{buffer}[\\{loc}]=\.{"\ "})$ \1\&{do}\5
$\\{incr}(\\{loc})$;\2\6
\&{if} $\\{loc}<\\{last}$ \1\&{then}\6
\&{begin} \37$\\{init\_terminal}\K\\{true}$;\5
\&{return};\C{return unless the line was all blank}\6
\&{end};\2\6
\&{if} $\\{line\_found}$ \1\&{then}\5
$\\{write\_ln}(\\{term\_out},\39\.{\'Please\ type\ the\ name\ of\ your\ input\
file.\'})$;\2\6
\\{wake\_up\_terminal};\5
$\\{write}(\\{term\_out},\39\.{\'**\'})$;\5
\\{update\_terminal};\5
$\\{buffer}[\\{first}]\K0$;\C{\\{input\_ln} may look at $\\{buffer}[%
\\{first}]$}\6
\&{if} $\R\\{input\_ln}(\\{term\_in},\39\\{true})$ \1\&{then}\C{this shouldn't
happen}\6
\&{begin} \37$\\{write\_ln}(\\{term\_out})$;\5
$\\{write}(\\{term\_out},\39\.{\'!\ End\ of\ file\ on\ the\ terminal...\ why?%
\'})$;\5
$\\{init\_terminal}\K\\{false}$;\5
\&{return};\6
\&{end};\2\6
$\\{line\_found}\K\\{true}$;\6
\&{end};\2\6
\4\\{exit}: \37\&{end};\par
\fi

\N38.  \[4] String handling.
Control sequence names and diagnostic messages are variable-length strings
of seven-bit characters. Since \PASCAL\ does not have a well-developed string
mechanism, \TeX\ does all of its string processing by homegrown methods.

Elaborate facilities for dynamic strings are not needed, so all of the
necessary operations can be handled with a simple data structure.
The array \\{str\_pool} contains all of the (seven-bit) ASCII codes in all
of the strings, and the array \\{str\_start} contains indices of the starting
points of each string. Strings are referred to by integer numbers, so that
string number \|s comprises the characters $\\{str\_pool}[\|j]$ for
$\\{str\_start}[\|s]\L\|j<\\{str\_start}[\|s+1]$. Additional integer variables
\\{pool\_ptr} and \\{str\_ptr} indicate the number of entries used so far
in \\{str\_pool} and \\{str\_start}, respectively; locations
$\\{str\_pool}[\\{pool\_ptr}]$ and $\\{str\_start}[\\{str\_ptr}]$ are
ready for the next string to be allocated.

String numbers 0 to 127 are reserved for strings that correspond to single
ASCII characters. This is in accordance with the conventions of \.{WEB},
which converts single-character strings into the ASCII code number of the
single character involved, while it converts other strings into integers
and builds a string pool file. Thus, when the string constant \.{"."} appears
in the program below, \.{WEB} converts it into the integer 46, which is the
ASCII code for a period, while \.{WEB} will convert a string like \.{"hello"}
into some integer greater than~127. String number 46 will presumably be the
single character `\..'; but some ASCII codes have no standard visible
representation, and \TeX\ sometimes needs to be able to print an arbitrary
ASCII character, so the first 128 strings are used to specify exactly what
should be printed for each of the 128 possibilities.

Elements of the \\{str\_pool} array must be ASCII codes that can actually be
printed; i.e., they must have an \\{xchr} equivalent in the local
character set. (However, the names of control sequences need not meet
this restriction, when they appear in \\{str\_pool}.)

\Y\P$\4\X18:Types in the outer block\X\mathrel{+}\S$\6
$\\{pool\_pointer}=0\to\\{pool\_size}$;\C{for variables that point into \\{str%
\_pool}}\6
$\\{str\_number}=0\to\\{max\_strings}$;\C{for variables that point into \\{str%
\_start}}\par
\fi

\M39. \P$\X13:Global variables\X\mathrel{+}\S$\6
\4\\{str\_pool}: \37\&{packed} \37\&{array} $[\\{pool\_pointer}]$ \1\&{of}\5
\\{ASCII\_code};\C{the characters}\2\6
\4\\{str\_start}: \37\&{array} $[\\{str\_number}]$ \1\&{of}\5
\\{pool\_pointer};\C{the starting pointers}\2\6
\4\\{pool\_ptr}: \37\\{pool\_pointer};\C{first unused position in \\{str%
\_pool}}\6
\4\\{str\_ptr}: \37\\{str\_number};\C{number of the current string being
created}\6
\4\\{init\_pool\_ptr}: \37\\{pool\_pointer};\C{the starting value of \\{pool%
\_ptr}}\6
\4\\{init\_str\_ptr}: \37\\{str\_number};\C{the starting value of \\{str\_ptr}}%
\par
\fi

\M40. Several of the elementary string operations are performed using \.{WEB}
macros instead of using \PASCAL\ procedures, because many of the
operations are done quite frequently and we want to avoid the
overhead of procedure calls. For example, here is
a simple macro that computes the length of a string.

\Y\P\D \37$\\{length}(\#)\S(\\{str\_start}[\#+1]-\\{str\_start}[\#])$\C{the
number of characters 	in string number \#}\par
\fi

\M41. The length of the current string is called \\{cur\_length}:

\Y\P\D \37$\\{cur\_length}\S(\\{pool\_ptr}-\\{str\_start}[\\{str\_ptr}])$\par
\fi

\M42. Strings are created by appending character codes to \\{str\_pool}.
The macro called \\{append\_char}, defined here, does not check to see if the
value of \\{pool\_ptr} has gotten too high; this test is supposed to be
made before \\{append\_char} is used. There is also a \\{flush\_char}
macro, which erases the last character appended.

To test if there is room to append \|l more characters to \\{str\_pool},
we shall write $\\{str\_room}(\|l)$, which aborts \TeX\ and gives an
apologetic error message if there isn't enough room.

\Y\P\D \37$\\{append\_char}(\#)\S$\C{put \\{ASCII\_code} \# at the end of %
\\{str\_pool}}\6
\&{begin} \37$\\{str\_pool}[\\{pool\_ptr}]\K\#$;\5
$\\{incr}(\\{pool\_ptr})$;\6
\&{end}\par
\P\D \37$\\{flush\_char}\S\\{decr}(\\{pool\_ptr})$\C{forget the last character
in the pool}\par
\P\D \37$\\{str\_room}(\#)\S$\C{make sure that the pool hasn't overflowed}\6
\&{begin} \37\&{if} $\\{pool\_ptr}+\#>\\{pool\_size}$ \1\&{then}\5
$\\{overflow}(\.{"pool\ size"},\39\\{pool\_size}-\\{init\_pool\_ptr})$;\2\6
\&{end}\par
\fi

\M43. Once a sequence of characters has been appended to \\{str\_pool}, it
officially becomes a string when the function \\{make\_string} is called.
This function returns the identification number of the new string as its
value.

\Y\P\4\&{function}\1\  \37\\{make\_string}: \37\\{str\_number};\C{current
string enters the pool}\2\6
\&{begin} \37\&{if} $\\{str\_ptr}=\\{max\_strings}$ \1\&{then}\5
$\\{overflow}(\.{"number\ of\ strings"},\39\\{max\_strings}-\\{init\_str%
\_ptr})$;\2\6
$\\{incr}(\\{str\_ptr})$;\5
$\\{str\_start}[\\{str\_ptr}]\K\\{pool\_ptr}$;\5
$\\{make\_string}\K\\{str\_ptr}-1$;\6
\&{end};\par
\fi

\M44. To destroy the most recently made string, we say \\{flush\_string}.

\Y\P\D \37$\\{flush\_string}\S$\1\6
\&{begin} \37$\\{decr}(\\{str\_ptr})$;\5
$\\{pool\_ptr}\K\\{str\_start}[\\{str\_ptr}]$;\6
\&{end}\2\par
\fi

\M45. The following subroutine compares string \|s with another string of the
same length that appears in \\{buffer} starting at position \|k;
the result is \\{true} if and only if the strings are equal.
Empirical tests indicate that \\{str\_eq\_buf} is used in such a way that
it tends to return \\{true} about 80 percent of the time.

\Y\P\4\&{function}\1\  \37$\\{str\_eq\_buf}(\|s:\\{str\_number};\,\35\|k:%
\\{integer})$: \37\\{boolean};\C{test equality of strings}\6
\4\&{label} \37\\{not\_found};\C{loop exit}\6
\4\&{var} \37\|j: \37\\{pool\_pointer};\C{running index}\6
\\{result}: \37\\{boolean};\C{result of comparison}\2\6
\&{begin} \37$\|j\K\\{str\_start}[\|s]$;\6
\&{while} $\|j<\\{str\_start}[\|s+1]$ \1\&{do}\6
\&{begin} \37\&{if} $\\{str\_pool}[\|j]\I\\{buffer}[\|k]$ \1\&{then}\6
\&{begin} \37$\\{result}\K\\{false}$;\5
\&{goto} \37\\{not\_found};\6
\&{end};\2\6
$\\{incr}(\|j)$;\5
$\\{incr}(\|k)$;\6
\&{end};\2\6
$\\{result}\K\\{true}$;\6
\4\\{not\_found}: \37$\\{str\_eq\_buf}\K\\{result}$;\6
\&{end};\par
\fi

\M46. Here is a similar routine, but it compares two strings in the string
pool,
and it does not assume that they have the same length.

\Y\P\4\&{function}\1\  \37$\\{str\_eq\_str}(\|s,\39\|t:\\{str\_number})$: \37%
\\{boolean};\C{test equality of strings}\6
\4\&{label} \37\\{not\_found};\C{loop exit}\6
\4\&{var} \37$\|j,\39\|k$: \37\\{pool\_pointer};\C{running indices}\6
\\{result}: \37\\{boolean};\C{result of comparison}\2\6
\&{begin} \37$\\{result}\K\\{false}$;\6
\&{if} $\\{length}(\|s)\I\\{length}(\|t)$ \1\&{then}\5
\&{goto} \37\\{not\_found};\2\6
$\|j\K\\{str\_start}[\|s]$;\5
$\|k\K\\{str\_start}[\|t]$;\6
\&{while} $\|j<\\{str\_start}[\|s+1]$ \1\&{do}\6
\&{begin} \37\&{if} $\\{str\_pool}[\|j]\I\\{str\_pool}[\|k]$ \1\&{then}\5
\&{goto} \37\\{not\_found};\2\6
$\\{incr}(\|j)$;\5
$\\{incr}(\|k)$;\6
\&{end};\2\6
$\\{result}\K\\{true}$;\6
\4\\{not\_found}: \37$\\{str\_eq\_str}\K\\{result}$;\6
\&{end};\par
\fi

\M47. The initial values of \\{str\_pool}, \\{str\_start}, \\{pool\_ptr},
and \\{str\_ptr} are computed by the \.{INITEX} program, based in part
on the information that \.{WEB} has output while processing \TeX.

\Y\P\&{init} \37\&{function}\1\  \37\\{get\_strings\_started}: \37\\{boolean};%
\C{initializes the string pool, 	but returns \\{false} if something goes wrong}%
\6
\4\&{label} \37$\\{done},\39\\{exit}$;\6
\4\&{var} \37$\|k,\39\|l$: \37$0\to127$;\C{small indices or counters}\6
$\|m,\39\|n$: \37\\{text\_char};\C{characters input from \\{pool\_file}}\6
\|g: \37\\{str\_number};\C{garbage}\6
\|a: \37\\{integer};\C{accumulator for check sum}\6
\|c: \37\\{boolean};\C{check sum has been checked}\2\6
\&{begin} \37$\\{pool\_ptr}\K0$;\5
$\\{str\_ptr}\K0$;\5
$\\{str\_start}[0]\K0$;\5
\X48:Make the first 128 strings\X;\6
\X51:Read the other strings from the \.{TEX.POOL} file and return \\{true}, or
give an error message and return \\{false}\X;\6
\4\\{exit}: \37\&{end};\6
\&{tini}\par
\fi

\M48. \P$\X48:Make the first 128 strings\X\S$\6
\&{for} $\|k\K0\mathrel{\&{to}}127$ \1\&{do}\6
\&{begin} \37\&{if} $(\X49\*:Character \|k cannot be printed\X)$ \1\&{then}\6
\&{begin} \37$\\{append\_char}(\.{"\↑"})$;\5
$\\{append\_char}(\.{"\↑"})$;\6
\&{if} $\|k<\O{100}$ \1\&{then}\5
$\\{append\_char}(\|k+\O{100})$\6
\4\&{else} $\\{append\_char}(\|k-\O{100})$;\2\6
\&{end}\6
\4\&{else} $\\{append\_char}(\|k)$;\2\6
$\|g\K\\{make\_string}$;\6
\&{end}\2\par
\U section~47.\fi

\M49\*. The first 128 strings will contain 95 standard ASCII characters, and
the
other 33 characters will be printed in three-symbol form like `\.{\↑\↑A}'
unless a system-dependent change is made here. Installations that have
an extended character set, where for example $\\{xchr}[\O{32}]=\hbox{\.{\'↑↑Z%
\'}}$,
would like string \O{32} to be the single character \O{32} instead of the
three characters \O{136}, \O{136}, \O{132} (\.{\↑\↑Z}). On the other hand,
even people with an extended character set will want to represent string
\O{15} by \.{\↑\↑M}, since \O{15} is \\{carriage\_return}; the idea is to
produce visible strings instead of tabs or line-feeds or carriage-returns
or bell-rings or characters that are treated anomalously in text files.

The boolean expression defined here should be \\{true} unless \TeX\ internal
code number~\|k corresponds to a non-troublesome visible symbol in the
local character set.  At MIT, for example, the appropriate formula would
be `$\|k\in[0,\O{10}\to\O{12},\O{14},\O{15},\O{33},\O{177}]$'.  If character %
\|k cannot be
printed, then character $\|k+\O{100}$ or $\|k-\O{100}$ must be printable; thus,
at
least 64 printable characters are needed.

\Y\P$\4\X49\*:Character \|k cannot be printed\X\S$\6
$(\|k<\.{"\ "})\V(\|k>\.{"\~"})$\par
\U section~48.\fi

\M50. When the \.{WEB} system program called \.{TANGLE} processes the %
\.{TEX.WEB}
description that you are now reading, it outputs the \PASCAL\ program
\.{TEX.PAS} and also a string pool file called \.{TEX.POOL}. The \.{INITEX}
program reads the latter file, where each string appears as a two-digit decimal
length followed by the string itself, and the information is recorded in
\TeX's string memory.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\&{init} \37\\{pool\_file}: \37\\{alpha\_file};\C{the string-pool file output
by \.{TANGLE}}\6
\&{tini}\par
\fi

\M51. \P\D \37$\\{bad\_pool}(\#)\S$\1\6
\&{begin} \37\\{wake\_up\_terminal};\5
$\\{write\_ln}(\\{term\_out},\39\#)$;\5
$\\{a\_close}(\\{pool\_file})$;\5
$\\{get\_strings\_started}\K\\{false}$;\5
\&{return};\6
\&{end}\2\par
\Y\P$\4\X51:Read the other strings from the \.{TEX.POOL} file and return %
\\{true}, or give an error message and return \\{false}\X\S$\6
$\\{name\_of\_file}\K\\{pool\_name}$;\C{we needn't set \\{name\_length}}\6
\&{if} $\\{a\_open\_in}(\\{pool\_file})$ \1\&{then}\6
\&{begin} \37$\|c\K\\{false}$;\6
\1\&{repeat} \37\X52:Read one string, but return \\{false} if the string memory
space is getting too tight for comfort\X;\6
\4\&{until}\5
\|c;\2\6
$\\{a\_close}(\\{pool\_file})$;\5
$\\{get\_strings\_started}\K\\{true}$;\6
\&{end}\6
\4\&{else} $\\{bad\_pool}(\.{\'!\ I\ can\'}\.{\'t\ read\ TEX.POOL.\'})$\2\par
\U section~47.\fi

\M52. \P$\X52:Read one string, but return \\{false} if the string memory space
is getting too tight for comfort\X\S$\6
\&{begin} \37\&{if} $\\{eof}(\\{pool\_file})$ \1\&{then}\5
$\\{bad\_pool}(\.{\'!\ TEX.POOL\ has\ no\ check\ sum.\'})$;\2\6
$\\{read}(\\{pool\_file},\39\|m,\39\|n)$;\C{read two digits of string length}\6
\&{if} $\|m=\.{\'*\'}$ \1\&{then}\5
\X53:Check the pool check sum\X\6
\4\&{else} \&{begin} \37\&{if} $(\\{xord}[\|m]<\.{"0"})\V(\\{xord}[\|m]>%
\.{"9"})\V\30(\\{xord}[\|n]<\.{"0"})\V(\\{xord}[\|n]>\.{"9"})$ \1\&{then}\5
$\\{bad\_pool}(\.{\'!\ TEX.POOL\ line\ doesn\'}\.{\'t\ begin\ with\ two\
digits.\'})$;\2\6
$\|l\K\\{xord}[\|m]\ast10+\\{xord}[\|n]-\.{"0"}\ast11$;\C{compute the length}\6
\&{if} $\\{pool\_ptr}+\|l+\\{string\_vacancies}>\\{pool\_size}$ \1\&{then}\5
$\\{bad\_pool}(\.{\'!\ You\ have\ to\ increase\ POOLSIZE.\'})$;\2\6
\&{for} $\|k\K1\mathrel{\&{to}}\|l$ \1\&{do}\6
\&{begin} \37\&{if} $\\{eoln}(\\{pool\_file})$ \1\&{then}\5
$\|m\K\.{\'\ \'}$\ \&{else} $\\{read}(\\{pool\_file},\39\|m)$;\2\6
$\\{append\_char}(\\{xord}[\|m])$;\6
\&{end};\2\6
$\\{read\_ln}(\\{pool\_file})$;\5
$\|g\K\\{make\_string}$;\6
\&{end};\2\6
\&{end}\par
\U section~51.\fi

\M53. The \.{WEB} operation \.{@\$} denotes the value that should be at the
end of this \.{TEX.POOL} file; any other value means that the wrong pool
file has been loaded.

\Y\P$\4\X53:Check the pool check sum\X\S$\6
\&{begin} \37$\|a\K0$;\5
$\|k\K1$;\6
\~ \1\&{loop}\ \&{begin} \37\&{if} $(\\{xord}[\|n]<\.{"0"})\V(\\{xord}[\|n]>%
\.{"9"})$ \1\&{then}\5
$\\{bad\_pool}(\.{\'!\ TEX.POOL\ check\ sum\ doesn\'}\.{\'t\ have\ nine\
digits.\'})$;\2\6
$\|a\K10\ast\|a+\\{xord}[\|n]-\.{"0"}$;\6
\&{if} $\|k=9$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
$\\{incr}(\|k)$;\5
$\\{read}(\\{pool\_file},\39\|n)$;\6
\&{end};\2\6
\4\\{done}: \37\&{if} $\|a\I\)$ \1\&{then}\5
$\\{bad\_pool}(\.{\'!\ TEX.POOL\ doesn\'}\.{\'t\ match;\ TANGLE\ me\ again.%
\'})$;\2\6
$\|c\K\\{true}$;\6
\&{end}\par
\U section~52.\fi

\N54.  \[5] On-line and off-line printing.
Messages that are sent to a user's terminal and to the transcript-log file
are produced by several `\\{print}' procedures. These procedures will
direct their output to a variety of places, based on the setting of
the global variable \\{selector}, which has the following possible
values:

\yskip
\hang \\{term\_and\_log}, the normal setting, prints on the terminal and on the
transcript file.

\hang \\{log\_only}, prints only on the transcript file.

\hang \\{term\_only}, prints only on the terminal.

\hang \\{no\_print}, doesn't print at all. This is used only in rare cases
before the transcript file is open.

\hang \\{pseudo}, puts output into a cyclic buffer that is used
by the \\{show\_context} routine; see that routine for the
reasoning behind this curious mode.

\hang \\{new\_string}, appends the output to the current string in the
string pool.

\hang 0 to 15, prints on one of the sixteen files for \.{\\write} output.

\yskip
\noindent The symbolic names `\\{term\_and\_log}', etc., have been assigned
numeric codes that satisfy the convenient relations $\\{no\_print}+1=\\{term%
\_only}$,
$\\{no\_print}+2=\\{log\_only}$, $\\{term\_only}+2=\\{log\_only}+1=\\{term\_and%
\_log}$.

Three additional global variables, \\{tally} and \\{term\_offset} and
\\{file\_offset}, record the number of characters that have been printed
since they were most recently cleared to zero. We use \\{tally} to record
the length of (possibly very long) stretches of printing; \\{term\_offset}
and \\{file\_offset}, on the other hand, keep track of how many characters
have appeared so far on the current line that has been output to the
terminal or to the transcript file, respectively.

\Y\P\D \37$\\{no\_print}=16$\C{\\{selector} setting that makes data disappear}%
\par
\P\D \37$\\{term\_only}=17$\C{printing is destined for the terminal only}\par
\P\D \37$\\{log\_only}=18$\C{printing is destined for the transcript file only}%
\par
\P\D \37$\\{term\_and\_log}=19$\C{normal \\{selector} setting}\par
\P\D \37$\\{pseudo}=20$\C{special \\{selector} setting for \\{show\_context}}%
\par
\P\D \37$\\{new\_string}=21$\C{printing is deflected to the string pool}\par
\P\D \37$\\{max\_selector}=21$\C{highest selector setting}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{log\_file}: \37\\{alpha\_file};\C{transcript of \TeX\ session}\6
\4\\{selector}: \37$0\to\\{max\_selector}$;\C{where to print a message}\6
\4\\{dig}: \37\&{array} $[0\to22]$ \1\&{of}\5
$0\to15$;\C{digits in a number being output}\2\6
\4\\{tally}: \37\\{integer};\C{the number of characters recently printed}\6
\4\\{term\_offset}: \37$0\to\\{max\_print\_line}$;\C{the number of characters
on the current terminal line}\6
\4\\{file\_offset}: \37$0\to\\{max\_print\_line}$;\C{the number of characters
on the current file line}\6
\4\\{trick\_buf}: \37\&{array} $[0\to\\{error\_line}]$ \1\&{of}\5
\\{ASCII\_code};\C{circular buffer for 	pseudoprinting}\2\6
\4\\{trick\_count}: \37\\{integer};\C{threshold for pseudoprinting, explained
later}\6
\4\\{first\_count}: \37\\{integer};\C{another variable for pseudoprinting}\par
\fi

\M55. \P$\X55:Initialize the output routines\X\S$\6
$\\{selector}\K\\{term\_only}$;\5
$\\{tally}\K0$;\5
$\\{term\_offset}\K0$;\5
$\\{file\_offset}\K0$;\par
\A sections~61, 528, and~533.
\U section~1332.\fi

\M56. Macro abbreviations for output to the terminal and to the log file are
defined here for convenience. Some systems need special conventions
for terminal output, and it is possible to adhere to those conventions
by changing \\{wterm}, \\{wterm\_ln}, and \\{wterm\_cr} in this section.

\Y\P\D \37$\\{wterm}(\#)\S\\{write}(\\{term\_out},\39\#)$\par
\P\D \37$\\{wterm\_ln}(\#)\S\\{write\_ln}(\\{term\_out},\39\#)$\par
\P\D \37$\\{wterm\_cr}\S\\{write\_ln}(\\{term\_out})$\par
\P\D \37$\\{wlog}(\#)\S\\{write}(\\{log\_file},\39\#)$\par
\P\D \37$\\{wlog\_ln}(\#)\S\\{write\_ln}(\\{log\_file},\39\#)$\par
\P\D \37$\\{wlog\_cr}\S\\{write\_ln}(\\{log\_file})$\par
\fi

\M57. To end a line of text output, we call \\{print\_ln}.

\Y\P$\4\X57:Basic printing procedures\X\S$\6
\4\&{procedure}\1\  \37\\{print\_ln};\C{prints an end-of-line}\2\6
\&{begin} \37\&{case} $\\{selector}$ \1\&{of}\6
\4\\{term\_and\_log}: \37\&{begin} \37\\{wterm\_cr};\5
\\{wlog\_cr};\5
$\\{term\_offset}\K0$;\5
$\\{file\_offset}\K0$;\6
\&{end};\6
\4\\{log\_only}: \37\&{begin} \37\\{wlog\_cr};\5
$\\{file\_offset}\K0$;\6
\&{end};\6
\4\\{term\_only}: \37\&{begin} \37\\{wterm\_cr};\5
$\\{term\_offset}\K0$;\6
\&{end};\6
\4$\\{no\_print},\39\\{pseudo},\39\\{new\_string}$: \37\\{do\_nothing};\6
\4\&{othercases} \37$\\{write\_ln}(\\{write\_file}[\\{selector}])$\2\6
\&{endcases};\6
\&{end};\C{\\{tally} is not affected}\par
\A sections~58, 59, 60, 62, 63, 64, 65, 262, 263, 518\*, 699, and~1355.
\U section~4.\fi

\M58. The \\{print\_char} procedure sends one character to the desired
destination,
using the \\{xchr} array to map it into an external character compatible with
\\{input\_ln}. All printing comes through \\{print\_ln} or \\{print\_char}.

\Y\P$\4\X57:Basic printing procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{print\_char}(\|s:\\{ASCII\_code})$;\C{prints a
single character}\6
\4\&{label} \37\\{exit};\2\6
\&{begin} \37\&{if} $\X244:Character \|s is the current new-line character\X$ %
\1\&{then}\6
\&{if} $\\{selector}<\\{pseudo}$ \1\&{then}\6
\&{begin} \37\\{print\_ln};\5
\&{return};\6
\&{end};\2\2\6
\&{case} $\\{selector}$ \1\&{of}\6
\4\\{term\_and\_log}: \37\&{begin} \37$\\{wterm}(\\{xchr}[\|s])$;\5
$\\{wlog}(\\{xchr}[\|s])$;\5
$\\{incr}(\\{term\_offset})$;\5
$\\{incr}(\\{file\_offset})$;\6
\&{if} $\\{term\_offset}=\\{max\_print\_line}$ \1\&{then}\6
\&{begin} \37\\{wterm\_cr};\5
$\\{term\_offset}\K0$;\6
\&{end};\2\6
\&{if} $\\{file\_offset}=\\{max\_print\_line}$ \1\&{then}\6
\&{begin} \37\\{wlog\_cr};\5
$\\{file\_offset}\K0$;\6
\&{end};\2\6
\&{end};\6
\4\\{log\_only}: \37\&{begin} \37$\\{wlog}(\\{xchr}[\|s])$;\5
$\\{incr}(\\{file\_offset})$;\6
\&{if} $\\{file\_offset}=\\{max\_print\_line}$ \1\&{then}\5
\\{print\_ln};\2\6
\&{end};\6
\4\\{term\_only}: \37\&{begin} \37$\\{wterm}(\\{xchr}[\|s])$;\5
$\\{incr}(\\{term\_offset})$;\6
\&{if} $\\{term\_offset}=\\{max\_print\_line}$ \1\&{then}\5
\\{print\_ln};\2\6
\&{end};\6
\4\\{no\_print}: \37\\{do\_nothing};\6
\4\\{pseudo}: \37\&{if} $\\{tally}<\\{trick\_count}$ \1\&{then}\5
$\\{trick\_buf}[\\{tally}\mathbin{\&{mod}}\\{error\_line}]\K\|s$;\2\6
\4\\{new\_string}: \37\&{begin} \37\&{if} $\\{pool\_ptr}<\\{pool\_size}$ \1%
\&{then}\5
$\\{append\_char}(\|s)$;\2\6
\&{end};\C{we drop characters if the string space is full}\6
\4\&{othercases} \37$\\{write}(\\{write\_file}[\\{selector}],\39\\{xchr}[\|s])$%
\2\6
\&{endcases};\6
$\\{incr}(\\{tally})$;\6
\4\\{exit}: \37\&{end};\par
\fi

\M59. An entire string is output by calling \\{print}. Note that if we are
outputting
the single standard ASCII character \.c, we could call $\\{print}(\.{"c"})$,
since
$\.{"c"}=99$ is the number of a single-character string, as explained above.
But
$\\{print\_char}(\.{"c"})$ is quicker, so \TeX\ goes directly to the \\{print%
\_char}
routine when it knows that this is safe. (The present implementation
assumes that it is always safe to print a visible ASCII character.)

\Y\P$\4\X57:Basic printing procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{print}(\|s:\\{integer})$;\C{prints string \|s}\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37\|j: \37\\{pool\_pointer};\C{current character code position}\2\6
\&{begin} \37\&{if} $\|s\G\\{str\_ptr}$ \1\&{then}\5
$\|s\K\.{"???"}$\C{this can't happen}\6
\4\&{else} \&{if} $\|s<128$ \1\&{then}\6
\&{if} $\|s<0$ \1\&{then}\5
$\|s\K\.{"???"}$\C{can't happen}\6
\4\&{else} \&{if} $(\X244:Character \|s is the current new-line character\X)$ %
\1\&{then}\6
\&{if} $\\{selector}<\\{pseudo}$ \1\&{then}\6
\&{begin} \37\\{print\_ln};\5
\&{return};\6
\&{end};\2\2\2\2\2\6
$\|j\K\\{str\_start}[\|s]$;\6
\&{while} $\|j<\\{str\_start}[\|s+1]$ \1\&{do}\6
\&{begin} \37$\\{print\_char}(\\{str\_pool}[\|j])$;\5
$\\{incr}(\|j)$;\6
\&{end};\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M60. Control sequence names might contain \\{ASCII\_code} values that can't
be printed using \\{print\_char}. Therefore we use \\{slow\_print} for them:

\Y\P$\4\X57:Basic printing procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{slow\_print}(\|s:\\{integer})$;\C{prints string \|s}%
\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37\|j: \37\\{pool\_pointer};\C{current character code position}\2\6
\&{begin} \37\&{if} $\|s\G\\{str\_ptr}$ \1\&{then}\5
$\|s\K\.{"???"}$\C{this can't happen}\6
\4\&{else} \&{if} $\|s<128$ \1\&{then}\6
\&{if} $\|s<0$ \1\&{then}\5
$\|s\K\.{"???"}$\C{can't happen}\6
\4\&{else} \&{if} $(\X244:Character \|s is the current new-line character\X)$ %
\1\&{then}\6
\&{if} $\\{selector}<\\{pseudo}$ \1\&{then}\6
\&{begin} \37\\{print\_ln};\5
\&{return};\6
\&{end};\2\2\2\2\2\6
$\|j\K\\{str\_start}[\|s]$;\6
\&{while} $\|j<\\{str\_start}[\|s+1]$ \1\&{do}\6
\&{begin} \37$\\{print}(\\{str\_pool}[\|j])$;\5
$\\{incr}(\|j)$;\6
\&{end};\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M61. Here is the very first thing that \TeX\ prints: a headline that
identifies
the version number and format package. The \\{term\_offset} variable is
temporarily
incorrect, but the discrepancy is not serious since we assume that the banner
and format identifier together will occupy at most \\{max\_print\_line}
character positions.

\Y\P$\4\X55:Initialize the output routines\X\mathrel{+}\S$\6
$\\{wterm}(\\{banner})$;\6
\&{if} $\\{format\_ident}=0$ \1\&{then}\5
$\\{wterm\_ln}(\.{\'\ (no\ format\ preloaded)\'})$\6
\4\&{else} \&{begin} \37$\\{print}(\\{format\_ident})$;\5
\\{print\_ln};\6
\&{end};\2\6
\\{update\_terminal};\par
\fi

\M62. The procedure \\{print\_nl} is like \\{print}, but it makes sure that the
string appears at the beginning of a new line.

\Y\P$\4\X57:Basic printing procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{print\_nl}(\|s:\\{str\_number})$;\C{prints string %
\|s at beginning of line}\2\6
\&{begin} \37\&{if} $((\\{term\_offset}>0)\W(\\{odd}(\\{selector})))\V\30((%
\\{file\_offset}>0)\W(\\{selector}\G\\{log\_only}))$ \1\&{then}\5
\\{print\_ln};\2\6
$\\{print}(\|s)$;\6
\&{end};\par
\fi

\M63. The procedure \\{print\_esc} prints a string that is preceded by
the user's escape character (which is usually a backslash).

\Y\P$\4\X57:Basic printing procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{print\_esc}(\|s:\\{str\_number})$;\C{prints escape
character, then \|s}\6
\4\&{var} \37\|c: \37\\{integer};\C{the escape character code}\2\6
\&{begin} \37\X243:Set variable \|c to the current escape character\X;\6
\&{if} $\|c\G0$ \1\&{then}\6
\&{if} $\|c<128$ \1\&{then}\5
$\\{print}(\|c)$;\2\2\6
$\\{print}(\|s)$;\6
\&{end};\par
\fi

\M64. An array of digits in the range $0\to15$ is printed by \\{print\_the%
\_digs}.

\Y\P$\4\X57:Basic printing procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{print\_the\_digs}(\|k:\\{eight\_bits})$;\C{prints $%
\\{dig}[\|k-1]$$\,\ldots\,$$\\{dig}[0]$}\2\6
\&{begin} \37\&{while} $\|k>0$ \1\&{do}\6
\&{begin} \37$\\{decr}(\|k)$;\6
\&{if} $\\{dig}[\|k]<10$ \1\&{then}\5
$\\{print\_char}(\.{"0"}+\\{dig}[\|k])$\6
\4\&{else} $\\{print\_char}(\.{"A"}-10+\\{dig}[\|k])$;\2\6
\&{end};\2\6
\&{end};\par
\fi

\M65. The following procedure, which prints out the decimal representation of a
given integer \|n, has been written carefully so that it works properly
if $\|n=0$ or if $(-\|n)$ would cause overflow. It does not apply $\mathbin{%
\&{mod}}$ or $\mathbin{\&{div}}$
to negative arguments, since such operations are not implemented consistently
by all \PASCAL\ compilers.

\Y\P$\4\X57:Basic printing procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{print\_int}(\|n:\\{integer})$;\C{prints an integer
in decimal form}\6
\4\&{var} \37\|k: \37$0\to23$;\C{index to current digit; we assume that $%
\|n<10↑{23}$}\6
\|m: \37\\{integer};\C{used to negate \|n in possibly dangerous cases}\2\6
\&{begin} \37$\|k\K0$;\6
\&{if} $\|n<0$ \1\&{then}\6
\&{begin} \37$\\{print\_char}(\.{"-"})$;\6
\&{if} $\|n>-100000000$ \1\&{then}\5
$\\{negate}(\|n)$\6
\4\&{else} \&{begin} \37$\|m\K-1-\|n$;\5
$\|n\K\|m\mathbin{\&{div}}10$;\5
$\|m\K(\|m\mathbin{\&{mod}}10)+1$;\5
$\|k\K1$;\6
\&{if} $\|m<10$ \1\&{then}\5
$\\{dig}[0]\K\|m$\6
\4\&{else} \&{begin} \37$\\{dig}[0]\K0$;\5
$\\{incr}(\|n)$;\6
\&{end};\2\6
\&{end};\2\6
\&{end};\2\6
\1\&{repeat} \37$\\{dig}[\|k]\K\|n\mathbin{\&{mod}}10$;\5
$\|n\K\|n\mathbin{\&{div}}10$;\5
$\\{incr}(\|k)$;\6
\4\&{until}\5
$\|n=0$;\2\6
$\\{print\_the\_digs}(\|k)$;\6
\&{end};\par
\fi

\M66. Here is a trivial procedure to print two digits; it is usually called
with
a parameter in the range $0\L\|n\L99$.

\Y\P\4\&{procedure}\1\  \37$\\{print\_two}(\|n:\\{integer})$;\C{prints two
least significant digits}\2\6
\&{begin} \37$\|n\K\\{abs}(\|n)\mathbin{\&{mod}}100$;\5
$\\{print\_char}(\.{"0"}+(\|n\mathbin{\&{div}}10))$;\5
$\\{print\_char}(\.{"0"}+(\|n\mathbin{\&{mod}}10))$;\6
\&{end};\par
\fi

\M67. Hexadecimal printing of nonnegative integers is accomplished by \\{print%
\_hex}.

\Y\P\4\&{procedure}\1\  \37$\\{print\_hex}(\|n:\\{integer})$;\C{prints a
positive integer in hexadecimal form}\6
\4\&{var} \37\|k: \37$0\to22$;\C{index to current digit; we assume that $0\L
n<16↑{22}$}\2\6
\&{begin} \37$\|k\K0$;\5
$\\{print\_char}(\.{""}\.{""})$;\6
\1\&{repeat} \37$\\{dig}[\|k]\K\|n\mathbin{\&{mod}}16$;\5
$\|n\K\|n\mathbin{\&{div}}16$;\5
$\\{incr}(\|k)$;\6
\4\&{until}\5
$\|n=0$;\2\6
$\\{print\_the\_digs}(\|k)$;\6
\&{end};\par
\fi

\M68. In certain situations, \TeX\ prints either a standard visible ASCII
character or its hexadecimal ASCII code.

\Y\P\4\&{procedure}\1\  \37$\\{print\_ASCII}(\|c:\\{integer})$;\C{prints a
character or its code}\2\6
\&{begin} \37\&{if} $(\|c\G0)\W(\|c\L127)$ \1\&{then}\5
$\\{print}(\|c)$\6
\4\&{else} \&{begin} \37$\\{print\_char}(\.{"["})$;\6
\&{if} $\|c<0$ \1\&{then}\5
$\\{print\_int}(\|c)$\ \&{else} $\\{print\_hex}(\|c)$;\2\6
$\\{print\_char}(\.{"]"})$;\6
\&{end};\2\6
\&{end};\par
\fi

\M69. Roman numerals are produced by the \\{print\_roman\_int} routine.
Readers
who like puzzles might enjoy trying to figure out how this tricky code
works; therefore no explanation will be given.

\Y\P\4\&{procedure}\1\  \37$\\{print\_roman\_int}(\|n:\\{integer})$;\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37$\|j,\39\|k$: \37\\{pool\_pointer};\C{mysterious indices into %
\\{str\_pool}}\6
$\|u,\39\|v$: \37\\{nonnegative\_integer};\C{mysterious numbers}\2\6
\&{begin} \37$\|j\K\\{str\_start}[\.{"m2d5c2l5x2v5i"}]$;\5
$\|v\K1000$;\6
\~ \1\&{loop}\ \&{begin} \37\&{while} $\|n\G\|v$ \1\&{do}\6
\&{begin} \37$\\{print\_char}(\\{str\_pool}[\|j])$;\5
$\|n\K\|n-\|v$;\6
\&{end};\2\6
\&{if} $\|n\L0$ \1\&{then}\5
\&{return};\C{nonpositive input produces no output}\2\6
$\|k\K\|j+2$;\5
$\|u\K\|v\mathbin{\&{div}}(\\{str\_pool}[\|k-1]-\.{"0"})$;\6
\&{if} $\\{str\_pool}[\|k-1]=\.{"2"}$ \1\&{then}\6
\&{begin} \37$\|k\K\|k+2$;\5
$\|u\K\|u\mathbin{\&{div}}(\\{str\_pool}[\|k-1]-\.{"0"})$;\6
\&{end};\2\6
\&{if} $\|n+\|u\G\|v$ \1\&{then}\6
\&{begin} \37$\\{print\_char}(\\{str\_pool}[\|k])$;\5
$\|n\K\|n+\|u$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\|j\K\|j+2$;\5
$\|v\K\|v\mathbin{\&{div}}(\\{str\_pool}[\|j-1]-\.{"0"})$;\6
\&{end};\2\6
\&{end};\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M70. The \\{print} subroutine will not print a string that is still being
created. The following procedure will.

\Y\P\4\&{procedure}\1\  \37\\{print\_current\_string};\C{prints a yet-unmade
string}\6
\4\&{var} \37\|j: \37\\{pool\_pointer};\C{points to current character code}\2\6
\&{begin} \37$\|j\K\\{str\_start}[\\{str\_ptr}]$;\6
\&{while} $\|j<\\{pool\_ptr}$ \1\&{do}\6
\&{begin} \37$\\{print\_char}(\\{str\_pool}[\|j])$;\5
$\\{incr}(\|j)$;\6
\&{end};\2\6
\&{end};\par
\fi

\M71\*. Here is a procedure that asks the user to type a line of input,
assuming that the \\{selector} setting is either \\{term\_only} or \\{term\_and%
\_log}.
The input is placed into locations \\{first} through $\\{last}-1$ of the
\\{buffer} array, and echoed on the transcript file if appropriate.

This procedure is never called when $\\{interaction}<\\{scroll\_mode}$.

\Y\P\D \37$\\{prompt\_input}(\#)\S$\1\6
\&{begin} \37\\{wake\_up\_terminal};\5
$\\{print}(\#)$;\5
\\{term\_input};\6
\&{end}\C{prints a string and gets a line of input}\2\par
\Y\P\4\&{procedure}\1\  \37\\{term\_input};\C{gets a line from the terminal}\6
\4\&{var} \37\|k: \37$0\to\\{buf\_size}$;\C{index into \\{buffer}}\2\6
\&{begin} \37\\{update\_terminal};\C{Now the user sees the prompt for sure}\6
$\\{buffer}[\\{first}]\K0$;\C{makes sure \\{input\_ln} doesn't find a \\{form%
\_feed}}\6
\&{if} $\R\\{input\_ln}(\\{term\_in},\39\\{true})$ \1\&{then}\5
$\\{fatal\_error}(\.{"End\ of\ file\ on\ the\ terminal!"})$;\2\6
$\\{term\_offset}\K0$;\C{the user's line ended with \<\rm return>}\6
$\\{decr}(\\{selector})$;\C{prepare to echo the input}\6
\&{if} $\\{last}\I\\{first}$ \1\&{then}\6
\&{for} $\|k\K\\{first}\mathrel{\&{to}}\\{last}-1$ \1\&{do}\5
$\\{print}(\\{buffer}[\|k])$;\2\2\6
\\{print\_ln};\5
$\\{incr}(\\{selector})$;\C{restore previous status}\6
\&{end};\par
\fi

\N72.  \[6] Reporting errors.
When something anomalous is detected, \TeX\ typically does something like this:
$$\vbox{\halign{#\hfil\cr
$\\{print\_err}(\.{"Something\ anomalous\ has\ been\ detected"})$;\cr
$\\{help3}(\.{"This\ is\ the\ first\ line\ of\ my\ offer\ to\ help."})$\cr
$(\.{"This\ is\ the\ second\ line.\ I\'m\ trying\ to"})$\cr
$(\.{"explain\ the\ best\ way\ for\ you\ to\ proceed."})$;\cr
\\{error};\cr}}$$
A two-line help message would be given using \\{help2}, etc.; these informal
helps should use simple vocabulary that complements the words used in the
official error message that was printed. (Outside of the U.S.A., the help
messages should preferably be translated into the local vernacular. Each
line of help is at most 60 characters long, in the present implementation,
so that \\{max\_print\_line} will not be exceeded.)

The \\{print\_err} procedure supplies a `\.!' before the official message,
and makes sure that the terminal is awake if a stop is going to occur.
The \\{error} procedure supplies a `\..' after the official message, then it
shows the location of the error; and if $\\{interaction}=\\{error\_stop%
\_mode}$,
it also enters into a dialog with the user, during which time the help
message may be printed.

\fi

\M73. The global variable \\{interaction} has four settings, representing
increasing
amounts of user interaction:

\Y\P\D \37$\\{batch\_mode}=0$\C{omits all stops and omits terminal output}\par
\P\D \37$\\{nonstop\_mode}=1$\C{omits all stops}\par
\P\D \37$\\{scroll\_mode}=2$\C{omits error stops}\par
\P\D \37$\\{error\_stop\_mode}=3$\C{stops at every opportunity to interact}\par
\P\D \37$\\{print\_err}(\#)\S$\1\6
\&{begin} \37\&{if} $\\{interaction}=\\{error\_stop\_mode}$ \1\&{then}\5
\\{wake\_up\_terminal};\2\6
$\\{print\_nl}(\.{"!\ "})$;\5
$\\{print}(\#)$;\6
\&{end}\2\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{interaction}: \37$\\{batch\_mode}\to\\{error\_stop\_mode}$;\C{current
level of interaction}\par
\fi

\M74. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{interaction}\K\\{error\_stop\_mode}$;\par
\fi

\M75. \TeX\ is careful not to call \\{error} when the print \\{selector}
setting
might be unusual. The only possible values of \\{selector} at the time of
error messages are

\yskip\hang\\{no\_print} (when $\\{interaction}=\\{batch\_mode}$
and \\{log\_file} not yet open);

\hang\\{term\_only} (when $\\{interaction}>\\{batch\_mode}$ and \\{log\_file}
not yet open);

\hang\\{log\_only} (when $\\{interaction}=\\{batch\_mode}$ and \\{log\_file} is
open);

\hang\\{term\_and\_log} (when $\\{interaction}>\\{batch\_mode}$ and \\{log%
\_file} is open).

\Y\P$\4\X75:Initialize the print \\{selector} based on \\{interaction}\X\S$\6
\&{if} $\\{interaction}=\\{batch\_mode}$ \1\&{then}\5
$\\{selector}\K\\{no\_print}$\ \&{else} $\\{selector}\K\\{term\_only}$\2\par
\U sections~1265 and~1337.\fi

\M76. A global variable \\{deletions\_allowed} is set \\{false} if the \\{get%
\_next}
routine is active when \\{error} is called; this ensures that \\{get\_next}
and related routines like \\{get\_token} will never be called recursively.

The global variable \\{history} records the worst level of error that
has been detected. It has four possible values: \\{spotless}, \\{warning%
\_issued},
\\{error\_message\_issued}, and \\{fatal\_error\_stop}.

Another global variable, \\{error\_count}, is increased by one when an
\\{error} occurs without an interactive dialog, and it is reset to zero at
the end of every paragraph.  If \\{error\_count} reaches 100, \TeX\ decides
that there is no point in continuing further.

\Y\P\D \37$\\{spotless}=0$\C{\\{history} value when nothing has been amiss yet}%
\par
\P\D \37$\\{warning\_issued}=1$\C{\\{history} value when \\{begin\_diagnostic}
has been called}\par
\P\D \37$\\{error\_message\_issued}=2$\C{\\{history} value when \\{error} has
been called}\par
\P\D \37$\\{fatal\_error\_stop}=3$\C{\\{history} value when termination was
premature}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{deletions\_allowed}: \37\\{boolean};\C{is it safe for \\{error} to call %
\\{get\_token}?}\6
\4\\{history}: \37$\\{spotless}\to\\{fatal\_error\_stop}$;\C{has the source
input been clean so far?}\6
\4\\{error\_count}: \37$-1\to100$;\C{the number of scrolled errors since the
	last paragraph ended}\par
\fi

\M77. The value of \\{history} is initially \\{fatal\_error\_stop}, but it will
be changed to \\{spotless} if \TeX\ survives the initialization process.

\Y\P$\4\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{deletions\_allowed}\K\\{true}$;\5
$\\{error\_count}\K0$;\C{\\{history} is initialized elsewhere}\par
\fi

\M78. Since errors can be detected almost anywhere in \TeX, we want to declare
the
error procedures near the beginning of the program. But the error procedures
in turn use some other procedures, which need to be declared \\{forward}
before we get to \\{error} itself.

It is possible for \\{error} to be called recursively if some error arises
when \\{get\_token} is being used to delete a token, or if some fatal error
occurs while \TeX\ is trying to fix a non-fatal one. But such recursion
is never more than one level deep.

\Y\P$\4\X34\*:Error handling procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{normalize\_selector};\5
\\{forward};\5
\hbox{\2}\6
\4\&{procedure}\1\  \37\\{get\_token};\5
\\{forward};\5
\hbox{\2}\6
\4\&{procedure}\1\  \37\\{term\_input};\5
\\{forward};\5
\hbox{\2}\6
\4\&{procedure}\1\  \37\\{show\_context};\5
\\{forward};\5
\hbox{\2}\6
\4\&{procedure}\1\  \37\\{begin\_file\_reading};\5
\\{forward};\5
\hbox{\2}\6
\4\&{procedure}\1\  \37\\{open\_log\_file};\5
\\{forward};\5
\hbox{\2}\6
\4\&{procedure}\1\  \37\\{close\_files\_and\_terminate};\5
\\{forward};\5
\hbox{\2}\6
\4\&{procedure}\1\  \37\\{clear\_for\_error\_prompt};\5
\\{forward};\5
\hbox{\2}\6
\4\&{procedure}\1\  \37\\{give\_err\_help};\5
\\{forward};\5
\hbox{\2}\6
\hbox{\4\hskip-\fontdimen2\font}\ \&{debug} \37\ \&{procedure}\1\  \37\\{debug%
\_help};\5
\\{forward};\ \&{gubed} \par
\fi

\M79. Individual lines of help are recorded in the array \\{help\_line}, which
contains entries in positions $0\to(\\{help\_ptr}-1)$. They should be printed
in reverse order, i.e., with $\\{help\_line}[0]$ last.

\Y\P\D \37$\\{hlp1}(\#)\S\\{help\_line}[0]\K\#$;\ \&{end} \par
\P\D \37$\\{hlp2}(\#)\S\\{help\_line}[1]\K\#$;\5
\\{hlp1}\par
\P\D \37$\\{hlp3}(\#)\S\\{help\_line}[2]\K\#$;\5
\\{hlp2}\par
\P\D \37$\\{hlp4}(\#)\S\\{help\_line}[3]\K\#$;\5
\\{hlp3}\par
\P\D \37$\\{hlp5}(\#)\S\\{help\_line}[4]\K\#$;\5
\\{hlp4}\par
\P\D \37$\\{hlp6}(\#)\S\\{help\_line}[5]\K\#$;\5
\\{hlp5}\par
\P\D \37$\\{help0}\S\\{help\_ptr}\K0$\C{sometimes there might be no help}\par
\P\D \37$\\{help1}\S$\ \&{begin} \37$\\{help\_ptr}\K1$;\5
\\{hlp1}\C{use this with one help line}\par
\P\D \37$\\{help2}\S$\ \&{begin} \37$\\{help\_ptr}\K2$;\5
\\{hlp2}\C{use this with two help lines}\par
\P\D \37$\\{help3}\S$\ \&{begin} \37$\\{help\_ptr}\K3$;\5
\\{hlp3}\C{use this with three help lines}\par
\P\D \37$\\{help4}\S$\ \&{begin} \37$\\{help\_ptr}\K4$;\5
\\{hlp4}\C{use this with four help lines}\par
\P\D \37$\\{help5}\S$\ \&{begin} \37$\\{help\_ptr}\K5$;\5
\\{hlp5}\C{use this with five help lines}\par
\P\D \37$\\{help6}\S$\ \&{begin} \37$\\{help\_ptr}\K6$;\5
\\{hlp6}\C{use this with six help lines}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{help\_line}: \37\&{array} $[0\to5]$ \1\&{of}\5
\\{str\_number};\C{helps for the next \\{error}}\2\6
\4\\{help\_ptr}: \37$0\to6$;\C{the number of help lines present}\6
\4\\{use\_err\_help}: \37\\{boolean};\C{should the \\{err\_help} list be
shown?}\par
\fi

\M80. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{help\_ptr}\K0$;\5
$\\{use\_err\_help}\K\\{false}$;\par
\fi

\M81. The \\{jump\_out} procedure just cuts across all active procedure levels
and
goes to \\{end\_of\_TEX}. This is the only nonlocal \&{goto}  statement in the
whole program. It is used when there is no recovery from a particular error.

Some \PASCAL\ compilers do not implement non-local \&{goto}  statements.
In such cases the body of \\{jump\_out} should simply be
`\\{close\_files\_and\_terminate};\thinspace' followed by a call on some system
procedure that quietly terminates the program.

\Y\P$\4\X34\*:Error handling procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{jump\_out};\2\6
\&{begin} \37\&{goto} \37\\{end\_of\_TEX};\6
\&{end};\par
\fi

\M82. Here now is the general \\{error} routine.

\Y\P$\4\X34\*:Error handling procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{error};\C{completes the job of error reporting}\6
\4\&{label} \37$\\{continue},\39\\{exit}$;\6
\4\&{var} \37\|c: \37\\{ASCII\_code};\C{what the user types}\6
$\\{s1},\39\\{s2},\39\\{s3},\39\\{s4}$: \37\\{integer};\C{used to save global
variables when deleting tokens}\2\6
\&{begin} \37\&{if} $\\{history}<\\{error\_message\_issued}$ \1\&{then}\5
$\\{history}\K\\{error\_message\_issued}$;\2\6
$\\{print\_char}(\.{"."})$;\5
\\{show\_context};\6
\&{if} $\\{interaction}=\\{error\_stop\_mode}$ \1\&{then}\5
\X83:Get user's advice and \&{return}\X;\2\6
$\\{incr}(\\{error\_count})$;\6
\&{if} $\\{error\_count}=100$ \1\&{then}\6
\&{begin} \37$\\{print\_nl}(\.{"(That\ makes\ 100\ errors;\ please\ try\
again.)"})$;\5
$\\{history}\K\\{fatal\_error\_stop}$;\5
\\{jump\_out};\6
\&{end};\2\6
\X90:Put help message on the transcript file\X;\6
\4\\{exit}: \37\&{end};\par
\fi

\M83. \P$\X83:Get user's advice and \&{return}\X\S$\6
\~ \1\&{loop}\ \&{begin} \37\\{continue}: \37\\{clear\_for\_error\_prompt};\5
$\\{prompt\_input}(\.{"?\ "})$;\6
\&{if} $\\{last}=\\{first}$ \1\&{then}\5
\&{return};\2\6
$\|c\K\\{buffer}[\\{first}]$;\6
\&{if} $\|c\G\.{"a"}$ \1\&{then}\5
$\|c\K\|c+\.{"A"}-\.{"a"}$;\C{convert to uppercase}\2\6
\X84\*:Interpret code \|c and \&{return} if done\X;\6
\&{end}\2\par
\U section~82.\fi

\M84\*. It is desirable to provide an `\.E' option here that gives the user
an easy way to return from \TeX\ to the system editor, with the offending
line ready to be edited. The present implementation does this by loading
the line editor with the appropriate call to the editor. We treat `\.T' the
same as `\.E', because other programs on this system invoke the editor
when the user says `\.T'.

There is a secret `\.D' option available when the debugging routines have
not been commented out.

\Y\P$\4\X84\*:Interpret code \|c and \&{return} if done\X\S$\6
\&{case} $\|c$ \1\&{of}\6
\4$\.{"0"},\39\.{"1"},\39\.{"2"},\39\.{"3"},\39\.{"4"},\39\.{"5"},\39\.{"6"},%
\39\.{"7"},\39\.{"8"},\39\.{"9"}$: \37\&{if} $\\{deletions\_allowed}$ \1%
\&{then}\5
\X88:Delete $\|c-\.{"0"}$ tokens and \&{goto} \\{continue}\X;\2\6
\hbox{\4\4}\ \&{debug} \37\.{"D"}: \37\&{begin} \37\\{debug\_help};\5
\&{goto} \37\\{continue};\ \&{end};\ \&{gubed}\6
\4$\.{"E"},\39\.{"T"}$: \37\&{if} $\\{base\_ptr}>0$ \1\&{then}\6
\&{begin} \37$\\{selector}\K\\{new\_string}$;\5
$\\{pool\_ptr}\K\\{str\_start}[\\{str\_ptr}]$;\5
$\\{print}(\.{"et\ "})$;\5
$\\{print}(\\{input\_stack}[\\{base\_ptr}].\\{name\_field})$;\5
$\\{print\_char}(\.{"/"})$;\5
$\\{print\_int}(\\{page})$;\5
$\\{print}(\.{"p/"})$;\5
$\\{print\_int}(\\{line})$;\5
$\\{print\_char}(\.{"l"})$;\5
$\\{print\_char}(\\{carriage\_return})$;\6
\&{if} $\\{str\_ptr}<\\{max\_strings}$ \1\&{then}\6
\&{begin} \37$\\{pseudo\_typein}\K\\{str\_ptr}$;\5
$\\{incr}(\\{str\_ptr})$;\5
$\\{str\_start}[\\{str\_ptr}]\K\\{pool\_ptr}$;\6
\&{end};\C{\\{make\_string} not declared \\{forward}}\2\6
$\\{selector}\K\\{term\_and\_log}$;\5
$\\{interaction}\K\\{scroll\_mode}$;\5
\\{jump\_out};\6
\&{end};\2\6
\4\.{"H"}: \37\X89:Print the help information and \&{goto} \\{continue}\X;\6
\4\.{"I"}: \37\X87:Introduce new material from the terminal and \&{return}\X;\6
\4$\.{"Q"},\39\.{"R"},\39\.{"S"}$: \37\X86:Change the interaction level and %
\&{return}\X;\6
\4\.{"X"}: \37\&{begin} \37$\\{interaction}\K\\{scroll\_mode}$;\5
\\{jump\_out};\6
\&{end};\6
\4\&{othercases} \37\\{do\_nothing}\2\6
\&{endcases};\6
\X85:Print the menu of available options\X\par
\U section~83.\fi

\M85. \P$\X85:Print the menu of available options\X\S$\6
\&{begin} \37$\\{print}(\.{"Type\ <return>\ to\ proceed,\ S\ to\ scroll\ future%
\ error\ messages,"})$;\6
$\\{print\_nl}(\.{"R\ to\ run\ without\ stopping,\ Q\ to\ run\ quietly,"})$;\6
$\\{print\_nl}(\.{"I\ to\ insert\ something,\ "})$;\6
\&{if} $\\{base\_ptr}>0$ \1\&{then}\5
$\\{print}(\.{"E\ to\ edit\ your\ file,"})$;\2\6
\&{if} $\\{deletions\_allowed}$ \1\&{then}\5
$\\{print\_nl}(\.{"1\ or\ ...\ or\ 9\ to\ ignore\ the\ next\ 1\ to\ 9\ tokens\
of\ input,"})$;\2\6
$\\{print\_nl}(\.{"H\ for\ help,\ X\ to\ quit."})$;\6
\&{end}\par
\U section~84\*.\fi

\M86. Here the author of \TeX\ apologizes for making use of the numerical
relation between \.{"Q"}, \.{"R"}, \.{"S"}, and the desired interaction
settings
\\{batch\_mode}, \\{nonstop\_mode}, \\{scroll\_mode}.

\Y\P$\4\X86:Change the interaction level and \&{return}\X\S$\6
\&{begin} \37$\\{error\_count}\K0$;\5
$\\{interaction}\K\\{batch\_mode}+\|c-\.{"Q"}$;\5
$\\{print}(\.{"OK,\ entering\ "})$;\6
\&{case} $\|c$ \1\&{of}\6
\4\.{"Q"}: \37\&{begin} \37$\\{print\_esc}(\.{"batchmode"})$;\5
$\\{decr}(\\{selector})$;\6
\&{end};\6
\4\.{"R"}: \37$\\{print\_esc}(\.{"nonstopmode"})$;\6
\4\.{"S"}: \37$\\{print\_esc}(\.{"scrollmode"})$;\2\6
\&{end};\C{there are no other cases}\6
$\\{print}(\.{"..."})$;\5
\\{print\_ln};\5
\\{update\_terminal};\5
\&{return};\6
\&{end}\par
\U section~84\*.\fi

\M87. When the following code is executed, $\\{buffer}[(\\{first}+1)\to(%
\\{last}-1)]$ may
contain the material inserted by the user; otherwise another prompt will
be given. In order to understand this part of the program fully, you need
to be familiar with \TeX's input stacks.

\Y\P$\4\X87:Introduce new material from the terminal and \&{return}\X\S$\6
\&{begin} \37\\{begin\_file\_reading};\C{enter a new syntactic level for
terminal input}\6
\C{now $\\{state}=\\{mid\_line}$, so an initial blank space will count as a
blank}\6
\&{if} $\\{last}>\\{first}+1$ \1\&{then}\6
\&{begin} \37$\\{loc}\K\\{first}+1$;\5
$\\{buffer}[\\{first}]\K\.{"\ "}$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{prompt\_input}(\.{"insert>"})$;\5
$\\{loc}\K\\{first}$;\6
\&{end};\2\6
$\\{first}\K\\{last}$;\5
$\\{cur\_input}.\\{limit\_field}\K\\{last}-1$;\C{no \\{end\_line\_char} ends
this line}\6
\&{return};\6
\&{end}\par
\U section~84\*.\fi

\M88. We allow deletion of up to 99 tokens at a time.

\Y\P$\4\X88:Delete $\|c-\.{"0"}$ tokens and \&{goto} \\{continue}\X\S$\6
\&{begin} \37$\\{s1}\K\\{cur\_tok}$;\5
$\\{s2}\K\\{cur\_cmd}$;\5
$\\{s3}\K\\{cur\_chr}$;\5
$\\{s4}\K\\{align\_state}$;\5
$\\{align\_state}\K1000000$;\5
$\\{OK\_to\_interrupt}\K\\{false}$;\6
\&{if} $(\\{last}>\\{first}+1)\W(\\{buffer}[\\{first}+1]\G\.{"0"})\W(%
\\{buffer}[\\{first}+1]\L\.{"9"})$ \1\&{then}\5
$\|c\K\|c\ast10+\\{buffer}[\\{first}+1]-\.{"0"}\ast11$\6
\4\&{else} $\|c\K\|c-\.{"0"}$;\2\6
\&{while} $\|c>0$ \1\&{do}\6
\&{begin} \37\\{get\_token};\C{one-level recursive call of \\{error} is
possible}\6
$\\{decr}(\|c)$;\6
\&{end};\2\6
$\\{cur\_tok}\K\\{s1}$;\5
$\\{cur\_cmd}\K\\{s2}$;\5
$\\{cur\_chr}\K\\{s3}$;\5
$\\{align\_state}\K\\{s4}$;\5
$\\{OK\_to\_interrupt}\K\\{true}$;\5
$\\{help2}(\.{"I\ have\ just\ deleted\ some\ text,\ as\ you\ asked."})$\6
$(\.{"You\ can\ now\ delete\ more,\ or\ insert,\ or\ whatever."})$;\5
\\{show\_context};\5
\&{goto} \37\\{continue};\6
\&{end}\par
\U section~84\*.\fi

\M89. \P$\X89:Print the help information and \&{goto} \\{continue}\X\S$\6
\&{begin} \37\&{if} $\\{use\_err\_help}$ \1\&{then}\6
\&{begin} \37\\{give\_err\_help};\5
$\\{use\_err\_help}\K\\{false}$;\6
\&{end}\6
\4\&{else} \&{begin} \37\&{if} $\\{help\_ptr}=0$ \1\&{then}\5
$\\{help2}(\.{"Sorry,\ I\ don\'t\ know\ how\ to\ help\ in\ this\ situation."})$%
\2\6
$\hbox{\kern1em}(\.{"Maybe\ you\ should\ try\ asking\ a\ human?"})$;\6
\1\&{repeat} \37$\\{decr}(\\{help\_ptr})$;\5
$\\{print}(\\{help\_line}[\\{help\_ptr}])$;\5
\\{print\_ln};\6
\4\&{until}\5
$\\{help\_ptr}=0$;\2\6
\&{end};\2\6
$\\{help4}(\.{"Sorry,\ I\ already\ gave\ what\ help\ I\ could..."})$\6
$(\.{"Maybe\ you\ should\ try\ asking\ a\ human?"})$\6
$(\.{"An\ error\ might\ have\ occurred\ before\ I\ noticed\ any\ problems."})$\6
$(\.{"\`\`If\ all\ else\ fails,\ read\ the\ instructions.\'\'"})$;\6
\&{goto} \37\\{continue};\6
\&{end}\par
\U section~84\*.\fi

\M90. \P$\X90:Put help message on the transcript file\X\S$\6
\&{if} $\\{interaction}>\\{batch\_mode}$ \1\&{then}\5
$\\{decr}(\\{selector})$;\C{avoid terminal output}\2\6
\&{if} $\\{use\_err\_help}$ \1\&{then}\6
\&{begin} \37\\{print\_ln};\5
\\{give\_err\_help};\6
\&{end}\6
\4\&{else} \&{while} $\\{help\_ptr}>0$ \1\&{do}\6
\&{begin} \37$\\{decr}(\\{help\_ptr})$;\5
$\\{print\_nl}(\\{help\_line}[\\{help\_ptr}])$;\6
\&{end};\2\2\6
\\{print\_ln};\6
\&{if} $\\{interaction}>\\{batch\_mode}$ \1\&{then}\5
$\\{incr}(\\{selector})$;\C{re-enable terminal output}\2\6
\\{print\_ln}\par
\U section~82.\fi

\M91. A dozen or so error messages end with a parenthesized integer, so we
save a teeny bit of program space by declaring the following procedure:

\Y\P\4\&{procedure}\1\  \37$\\{int\_error}(\|n:\\{integer})$;\2\6
\&{begin} \37$\\{print}(\.{"\ ("})$;\5
$\\{print\_int}(\|n)$;\5
$\\{print\_char}(\.{")"})$;\5
\\{error};\6
\&{end};\par
\fi

\M92. In anomalous cases, the print selector might be in an unknown state;
the following subroutine is called to fix things just enough to keep
running a bit longer.

The normal idea of \\{batch\_mode} is that nothing at all should be written
on the terminal. However, in the unusual case that a fatal error has
occurred but no log file could be opened, we make an exception and allow
an explanatory message to be seen.

\Y\P\4\&{procedure}\1\  \37\\{normalize\_selector};\2\6
\&{begin} \37\&{if} $\\{job\_name}>0$ \1\&{then}\5
$\\{selector}\K\\{term\_and\_log}$\6
\4\&{else} $\\{selector}\K\\{term\_only}$;\2\6
\&{if} $\\{job\_name}=0$ \1\&{then}\5
\\{open\_log\_file};\2\6
\&{if} $\\{interaction}=\\{batch\_mode}$ \1\&{then}\5
$\\{decr}(\\{selector})$;\2\6
\&{end};\par
\fi

\M93. The following procedure prints \TeX's last words before dying.

\Y\P\D \37$\\{succumb}\S$\1\6
\&{begin} \37\&{if} $\\{interaction}=\\{error\_stop\_mode}$ \1\&{then}\5
$\\{interaction}\K\\{scroll\_mode}$;\C{no more interaction}\2\6
\\{error};\6
\&{debug} \37\&{if} $\\{interaction}>\\{batch\_mode}$ \1\&{then}\5
\\{debug\_help};\ \2\6
\&{gubed}\6
$\\{history}\K\\{fatal\_error\_stop}$;\5
\\{jump\_out};\C{irrecoverable error}\6
\&{end}\2\par
\Y\P$\4\X34\*:Error handling procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{fatal\_error}(\|s:\\{str\_number})$;\C{prints \|s,
and that's it}\2\6
\&{begin} \37\\{normalize\_selector};\6
$\\{print\_err}(\.{"Emergency\ stop"})$;\5
$\\{help1}(\|s)$;\5
\\{succumb};\6
\&{end};\par
\fi

\M94. Here is the most dreaded error message.

\Y\P$\4\X34\*:Error handling procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{overflow}(\|s:\\{str\_number};\,\35\|n:%
\\{integer})$;\C{stop due to finiteness}\2\6
\&{begin} \37\\{normalize\_selector};\5
$\\{print\_err}(\.{"TeX\ capacity\ exceeded,\ sorry\ ["})$;\5
$\\{print}(\|s)$;\5
$\\{print\_char}(\.{"="})$;\5
$\\{print\_int}(\|n)$;\5
$\\{print\_char}(\.{"]"})$;\5
$\\{help2}(\.{"If\ you\ really\ absolutely\ need\ more\ capacity,"})$\6
$(\.{"you\ can\ ask\ a\ wizard\ to\ enlarge\ me."})$;\5
\\{succumb};\6
\&{end};\par
\fi

\M95. The program might sometime run completely amok, at which point there is
no choice but to stop. If no previous error has been detected, that's bad
news; a message is printed that is really intended for the \TeX\
maintenance person instead of the user (unless the user has been
particularly diabolical).  The index entries for `this can't happen' may
help to pinpoint the problem.

\Y\P$\4\X34\*:Error handling procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{confusion}(\|s:\\{str\_number})$;\C{consistency
check violated; \|s tells where}\2\6
\&{begin} \37\\{normalize\_selector};\6
\&{if} $\\{history}<\\{error\_message\_issued}$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"This\ can\'t\ happen\ ("})$;\5
$\\{print}(\|s)$;\5
$\\{print\_char}(\.{")"})$;\5
$\\{help1}(\.{"I\'m\ broken.\ Please\ show\ this\ to\ someone\ who\ can\ fix\
can\ fix"})$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{print\_err}(\.{"I\ can\'t\ go\ on\ meeting\ you\
like\ this"})$;\5
$\\{help2}(\.{"One\ of\ your\ faux\ pas\ seems\ to\ have\ wounded\ me\
deeply..."})$\6
$(\.{"in\ fact,\ I\'m\ barely\ conscious.\ Please\ fix\ it\ and\ try\
again."})$;\6
\&{end};\2\6
\\{succumb};\6
\&{end};\par
\fi

\M96. Users occasionally want to interrupt \TeX\ while it's running.
If the \PASCAL\ runtime system allows this, one can implement
a routine that sets the global variable \\{interrupt} to some nonzero value
when such an interrupt is signalled. Otherwise there is probably at least
a way to make \\{interrupt} nonzero using the \PASCAL\ debugger.

\Y\P\D \37$\\{check\_interrupt}\S$\1\6
\&{begin} \37\&{if} $\\{interrupt}\I0$ \1\&{then}\5
\\{pause\_for\_instructions};\2\6
\&{end}\2\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{interrupt}: \37\\{integer};\C{should \TeX\ pause for instructions?}\6
\4\\{OK\_to\_interrupt}: \37\\{boolean};\C{should interrupts be observed?}\par
\fi

\M97. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{interrupt}\K0$;\5
$\\{OK\_to\_interrupt}\K\\{true}$;\par
\fi

\M98. When an interrupt has been detected, the program goes into its
highest interaction level and lets the user have the full flexibility of
the \\{error} routine.  \TeX\ checks for interrupts only at times when it is
safe to do this.

\Y\P\4\&{procedure}\1\  \37\\{pause\_for\_instructions};\2\6
\&{begin} \37\&{if} $\\{OK\_to\_interrupt}$ \1\&{then}\6
\&{begin} \37$\\{interaction}\K\\{error\_stop\_mode}$;\6
\&{if} $(\\{selector}=\\{log\_only})\V(\\{selector}=\\{no\_print})$ \1\&{then}\5
$\\{incr}(\\{selector})$;\2\6
$\\{print\_err}(\.{"Interruption"})$;\5
$\\{help3}(\.{"You\ rang?"})$\6
$(\.{"Try\ to\ insert\ some\ instructions\ for\ me\ (e.g.,\`I\\showlists%
\'),"})$\6
$(\.{"unless\ you\ just\ want\ to\ quit\ by\ typing\ \`X\'."})$;\5
$\\{deletions\_allowed}\K\\{false}$;\5
\\{error};\5
$\\{deletions\_allowed}\K\\{true}$;\5
$\\{interrupt}\K0$;\6
\&{end};\2\6
\&{end};\par
\fi

\N99.  \[7] Arithmetic with scaled dimensions.
The principal computations performed by \TeX\ are done entirely in terms of
integers less than $2↑{31}$ in magnitude; and divisions are done only when both
dividend and divisor are nonnegative. Thus, the arithmetic specified in this
program can be carried out in exactly the same way on a wide variety of
computers, including some small ones. Why? Because the arithmetic
calculations need to be spelled out precisely in order to guarantee that
\TeX\ will produce identical output on different machines. If some
quantities were rounded differently in different implementations, we would
find that line breaks and even page breaks might occur in different places.
Hence the arithmetic of \TeX\ has been designed with care, and systems that
claim to be implementations of \TeX82 should follow precisely the
calculations as they appear in the present program.

(Actually there are three places where \TeX\ uses $\mathbin{\&{div}}$ with a
possibly negative
numerator. These are harmless; see $\mathbin{\&{div}}$ in the index. Also if
the user
sets the \.{\\time} or the \.{\\year} to a negative value, some diagnostic
information will involve negative-numerator division. The same remarks
apply for $\mathbin{\&{mod}}$ as well as for $\mathbin{\&{div}}$.)

\fi

\M100. Here is a routine that calculates half of an integer, using an
unambiguous convention with respect to signed odd numbers.

\Y\P\4\&{function}\1\  \37$\\{half}(\|x:\\{integer})$: \37\\{integer};\2\6
\&{begin} \37\&{if} $\\{odd}(\|x)$ \1\&{then}\5
$\\{half}\K(\|x+1)\mathbin{\&{div}}2$\6
\4\&{else} $\\{half}\K\|x\mathbin{\&{div}}2$;\2\6
\&{end};\par
\fi

\M101. Fixed-point arithmetic is done on {\sl scaled integers\/} that are
multiples
of $2↑{-16}$. In other words, a binary point is assumed to be sixteen bit
positions from the right end of a binary computer word.

\Y\P\D \37$\\{unity}\S\O{200000}$\C{$2↑{16}$, represents 1.00000}\par
\P\D \37$\\{two}\S\O{400000}$\C{$2↑{17}$, represents 2.00000}\par
\Y\P$\4\X18:Types in the outer block\X\mathrel{+}\S$\6
$\\{scaled}=\\{integer}$;\C{this type is used for scaled integers}\6
$\\{nonnegative\_integer}=0\to\O{17777777777}$;\C{$0\L x<2↑{31}$}\6
$\\{small\_number}=0\to63$;\C{this type is self-explanatory}\par
\fi

\M102. The following function is used to create a scaled integer from a decimal
fraction $(.d_0d_1\ldots d_{k-1})$, where $0\L\|k\L17$. The digit $d_i$ is
given in $\\{dig}[\|i]$, and the calculation produces a correctly rounded
result.

\Y\P\4\&{function}\1\  \37$\\{round\_decimals}(\|k:\\{small\_number})$: \37%
\\{scaled};\C{converts a decimal fraction}\6
\4\&{var} \37\|a: \37\\{integer};\C{the accumulator}\2\6
\&{begin} \37$\|a\K0$;\6
\&{while} $\|k>0$ \1\&{do}\6
\&{begin} \37$\\{decr}(\|k)$;\5
$\|a\K(\|a+\\{dig}[\|k]\ast\\{two})\mathbin{\&{div}}10$;\6
\&{end};\2\6
$\\{round\_decimals}\K(\|a+1)\mathbin{\&{div}}2$;\6
\&{end};\par
\fi

\M103. Conversely, here is a procedure analogous to \\{print\_int}. If the
output
of this procedure is subsequently read by \TeX\ and converted by the
\\{round\_decimals} routine above, it turns out that the original value will
be reproduced exactly; the ``simplest'' such decimal number is output,
but there is always at least one digit following the decimal point.

The invariant relation in the \&{repeat} loop is that a sequence of
decimal digits yet to be printed will yield the original number if and only if
they form a fraction~$f$ in the range $s-\delta\L10\cdot2↑{16}f<s$.
We can stop if and only if $f=0$ satisfies this condition; the loop will
terminate before $s$ can possibly become zero.

\Y\P\4\&{procedure}\1\  \37$\\{print\_scaled}(\|s:\\{scaled})$;\C{prints scaled
real, rounded to five 	digits}\6
\4\&{var} \37\\{delta}: \37\\{scaled};\C{amount of allowable inaccuracy}\2\6
\&{begin} \37\&{if} $\|s<0$ \1\&{then}\6
\&{begin} \37$\\{print\_char}(\.{"-"})$;\5
$\\{negate}(\|s)$;\C{print the sign, if negative}\6
\&{end};\2\6
$\\{print\_int}(\|s\mathbin{\&{div}}\\{unity})$;\C{print the integer part}\6
$\\{print\_char}(\.{"."})$;\5
$\|s\K10\ast(\|s\mathbin{\&{mod}}\\{unity})+5$;\5
$\\{delta}\K10$;\6
\1\&{repeat} \37\&{if} $\\{delta}>\\{unity}$ \1\&{then}\5
$\|s\K\|s+\O{100000}-(\\{delta}\mathbin{\&{div}}2)$;\C{round the last digit}\2\6
$\\{print\_char}(\.{"0"}+(\|s\mathbin{\&{div}}\\{unity}))$;\5
$\|s\K10\ast(\|s\mathbin{\&{mod}}\\{unity})$;\5
$\\{delta}\K\\{delta}\ast10$;\6
\4\&{until}\5
$\|s\L\\{delta}$;\2\6
\&{end};\par
\fi

\M104. Physical sizes that a \TeX\ user specifies for portions of documents are
represented internally as scaled points. Thus, if we define an `sp' (scaled
point) as a unit equal to $2↑{-16}$ printer's points, every dimension
inside of \TeX\ is an integer number of sp. There are exactly
4,736,286.72 sp per inch.  Users are not allowed to specify dimensions
larger than $2↑{30}-1$ sp, which is a distance of about 18.892 feet (5.7583
meters); two such quantities can be added without overflow on a 32-bit
computer.

The present implementation of \TeX\ does not check for overflow when
dimensions are added or subtracted. This could be done by inserting a
few dozen tests of the form `\ignorespaces \&{if} $\|x\G\O{10000000000}$ %
\&{then} \hbox{\\{report\_overflow}}', but the chance of overflow is so remote
that
such tests do not seem worthwhile.

\TeX\ needs to do only a few arithmetic operations on scaled quantities,
other than addition and subtraction, and the following subroutines do most of
the work. A single computation might use several subroutine calls, and it is
desirable to avoid producing multiple error messages in case of arithmetic
overflow; so the routines set the global variable \\{arith\_error} to \\{true}
instead of reporting errors directly to the user. Another global variable,
\\{remainder}, holds the remainder after a division.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{arith\_error}: \37\\{boolean};\C{has arithmetic overflow occurred
recently?}\6
\4\\{remainder}: \37\\{scaled};\C{amount subtracted to get an exact division}%
\par
\fi

\M105. The first arithmetical subroutine we need computes $nx+y$, where \|x
and~\|y are \\{scaled} and \|n is an integer.

\Y\P\4\&{function}\1\  \37$\\{nx\_plus\_y}(\|n:\\{integer};\,\35\|x,\39\|y:%
\\{scaled})$: \37\\{scaled};\2\6
\&{begin} \37\&{if} $\|n<0$ \1\&{then}\6
\&{begin} \37$\\{negate}(\|x)$;\5
$\\{negate}(\|n)$;\6
\&{end};\2\6
\&{if} $\|n=0$ \1\&{then}\5
$\\{nx\_plus\_y}\K\|y$\6
\4\&{else} \&{if} $((\|x\L(\O{7777777777}-\|y)\mathbin{\&{div}}\|n)\W(-\|x\L(%
\O{7777777777}+\|y)\mathbin{\&{div}}\|n))$ \1\&{then}\5
$\\{nx\_plus\_y}\K\|n\ast\|x+\|y$\6
\4\&{else} \&{begin} \37$\\{arith\_error}\K\\{true}$;\5
$\\{nx\_plus\_y}\K0$;\6
\&{end};\2\2\6
\&{end};\par
\fi

\M106. We also need to divide scaled dimensions by integers.

\Y\P\4\&{function}\1\  \37$\\{x\_over\_n}(\|x:\\{scaled};\,\35\|n:%
\\{integer})$: \37\\{scaled};\6
\4\&{var} \37\\{negative}: \37\\{boolean};\C{should \\{remainder} be negated?}%
\2\6
\&{begin} \37$\\{negative}\K\\{false}$;\6
\&{if} $\|n=0$ \1\&{then}\6
\&{begin} \37$\\{arith\_error}\K\\{true}$;\5
$\\{x\_over\_n}\K0$;\5
$\\{remainder}\K\|x$;\6
\&{end}\6
\4\&{else} \&{begin} \37\&{if} $\|n<0$ \1\&{then}\6
\&{begin} \37$\\{negate}(\|x)$;\5
$\\{negate}(\|n)$;\5
$\\{negative}\K\\{true}$;\6
\&{end};\2\6
\&{if} $\|x\G0$ \1\&{then}\6
\&{begin} \37$\\{x\_over\_n}\K\|x\mathbin{\&{div}}\|n$;\5
$\\{remainder}\K\|x\mathbin{\&{mod}}\|n$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{x\_over\_n}\K-((-\|x)\mathbin{\&{div}}\|n)$;\5
$\\{remainder}\K-((-\|x)\mathbin{\&{mod}}\|n)$;\6
\&{end};\2\6
\&{end};\2\6
\&{if} $\\{negative}$ \1\&{then}\5
$\\{negate}(\\{remainder})$;\2\6
\&{end};\par
\fi

\M107. Then comes the multiplication of a scaled number by a fraction $\|n/%
\|d$,
where \|n and \|d are nonnegative integers $\L\hbox{$2↑{16}$}$ and \|d is
positive. It would be too dangerous to multiply by~\|n and then divide
by~\|d, in separate operations, since overflow might well occur; and it
would be too inaccurate to divide by \|d and then multiply by \|n. Hence
this subroutine simulates 1.5-precision arithmetic.

\Y\P\4\&{function}\1\  \37$\\{xn\_over\_d}(\|x:\\{scaled};\,\35\|n,\39\|d:%
\\{integer})$: \37\\{scaled};\6
\4\&{var} \37\\{positive}: \37\\{boolean};\C{was $\|x\G0$?}\6
$\|t,\39\|u,\39\|v$: \37\\{nonnegative\_integer};\C{intermediate quantities}\2\6
\&{begin} \37\&{if} $\|x\G0$ \1\&{then}\5
$\\{positive}\K\\{true}$\6
\4\&{else} \&{begin} \37$\\{negate}(\|x)$;\5
$\\{positive}\K\\{false}$;\6
\&{end};\2\6
$\|t\K(\|x\mathbin{\&{mod}}\O{100000})\ast\|n$;\5
$\|u\K(\|x\mathbin{\&{div}}\O{100000})\ast\|n+(\|t\mathbin{\&{div}}%
\O{100000})$;\5
$\|v\K(\|u\mathbin{\&{mod}}\|d)\ast\O{100000}+(\|t\mathbin{\&{mod}}%
\O{100000})$;\6
\&{if} $\|u\mathbin{\&{div}}\|d\G\O{100000}$ \1\&{then}\5
$\\{arith\_error}\K\\{true}$\6
\4\&{else} $\|u\K\O{100000}\ast(\|u\mathbin{\&{div}}\|d)+(\|v\mathbin{\&{div}}%
\|d)$;\2\6
\&{if} $\\{positive}$ \1\&{then}\6
\&{begin} \37$\\{xn\_over\_d}\K\|u$;\5
$\\{remainder}\K\|v\mathbin{\&{mod}}\|d$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{xn\_over\_d}\K-\|u$;\5
$\\{remainder}\K-(\|v\mathbin{\&{mod}}\|d)$;\6
\&{end};\2\6
\&{end};\par
\fi

\M108. The next subroutine is used to compute the ``badness'' of glue, when a
total~\|t is supposed to be made from amounts that sum to~\|s.  According
to {\sl The \TeX book}, the badness of this situation is $100(t/s)↑3$;
however, badness is simply a heuristic, so we need not squeeze out the
last drop of accuracy when computing it. All we really want is an
approximation that has similar properties.

The actual method used to compute the badness is easier to read from the
program than to describe in words. It produces an integer value that is a
reasonably close approximation to $100(t/s)↑3$, and all implementations
of \TeX\ should use precisely this method. Any badness of $2↑{13}$ or more is
treated as infinitely bad, and represented by 10000.

It is not difficult to prove that $$\hbox{$\\{badness}(\|t+1,\|s)\G\\{badness}(%
\|t,\|s)\G\\{badness}(\|t,\|s+1)$}.$$ The badness function defined here is
capable of
computing at most 1095 distinct values, but that is plenty.

\Y\P\D \37$\\{inf\_bad}=10000$\C{infinitely bad value}\par
\Y\P\4\&{function}\1\  \37$\\{badness}(\|t,\39\|s:\\{scaled})$: \37%
\\{halfword};\C{compute badness, given $\|t\G0$}\6
\4\&{var} \37\|r: \37\\{integer};\C{approximation to $\alpha t/s$, where $%
\alpha↑3\approx 	100\cdot2↑{18}$}\2\6
\&{begin} \37\&{if} $\|t=0$ \1\&{then}\5
$\\{badness}\K0$\6
\4\&{else} \&{if} $\|s\L0$ \1\&{then}\5
$\\{badness}\K\\{inf\_bad}$\6
\4\&{else} \&{begin} \37\&{if} $\|t\L7230584$ \1\&{then}\5
$\|r\K(\|t\ast297)\mathbin{\&{div}}\|s$\C{$297↑3=99.94\times2↑{18}$}\6
\4\&{else} \&{if} $\|s\G1663497$ \1\&{then}\5
$\|r\K\|t\mathbin{\&{div}}(\|s\mathbin{\&{div}}297)$\6
\4\&{else} $\|r\K\|t$;\2\2\6
\&{if} $\|r>1290$ \1\&{then}\5
$\\{badness}\K\\{inf\_bad}$\C{$1290↑3<2↑{31}<1291↑3$}\6
\4\&{else} $\\{badness}\K(\|r\ast\|r\ast\|r+\O{400000})\mathbin{\&{div}}%
\O{1000000}$;\2\6
\&{end};\C{that was $r↑3/2↑{18}$, rounded to the nearest integer}\2\2\6
\&{end};\par
\fi

\M109. When \TeX\ ``packages'' a list into a box, it needs to calculate the
proportionality ratio by which the glue inside the box should stretch
or shrink. This calculation does not affect \TeX's decision making,
so the precise details of rounding, etc., in the glue calculation are not
of critical importance for the consistency of results on different computers.

We shall use the type \\{glue\_ratio} for such proportionality ratios.
A glue ratio should take the same amount of memory as an
\\{integer} (usually 32 bits) if it is to blend smoothly with \TeX's
other data structures. Thus \\{glue\_ratio} should be equivalent to
\\{short\_real} in some implementations of \PASCAL. Alternatively,
it is possible to deal with glue ratios using nothing but fixed-point
arithmetic; see {\sl TUGboat \bf3},1 (February 1982), 10--27. (But the
routines cited there must be modified to allow negative glue ratios.)

\Y\P\D \37$\\{set\_glue\_ratio\_zero}(\#)\S\#\K0.0$\C{store the representation
of zero ratio}\par
\P\D \37$\\{set\_glue\_ratio\_one}(\#)\S\#\K1.0$\C{store the representation of
unit ratio}\par
\P\D \37$\\{float}(\#)\S\#$\C{convert from \\{glue\_ratio} to type \\{real}}\par
\P\D \37$\\{unfloat}(\#)\S\#$\C{convert from \\{real} to type \\{glue\_ratio}}%
\par
\P\D \37$\\{float\_constant}(\#)\S\#.0$\C{convert \\{integer} constant to %
\\{real}}\par
\Y\P$\4\X18:Types in the outer block\X\mathrel{+}\S$\6
$\\{glue\_ratio}=\\{real}$;\C{one-word representation of a glue expansion
factor}\par
\fi

\N110\*.  \[8] Packed data.
In order to make efficient use of storage space, \TeX\ bases its major data
structures on a \\{memory\_word}, which contains either a (signed) integer,
possibly scaled, or an (unsigned) \\{glue\_ratio}, or a small number of
fields that are one half or one quarter of the size used for storing
integers.

If \|x is a variable of type \\{memory\_word}, it contains up to four
fields that can be referred to as follows:
$$\vbox{\halign{\hfil#&#\hfil&#\hfil\cr
\|x&.\\{int}&(an \\{integer})\cr
\|x&.\\{sc}\qquad&(a \\{scaled} integer)\cr
\|x&.\\{gr}&(a \\{glue\_ratio})\cr
\|x.\\{hh}.\\{lh}, \|x.\\{hh}&.\\{rh}&(two halfword fields)\cr
\|x.\\{hh}.\\{b0}, \|x.\\{hh}.\\{b1}, \|x.\\{hh}&.\\{rh}&(two quarterword
fields, one halfword
field)\cr
\|x.\\{qqqq}.\\{b0}, \|x.\\{qqqq}.\\{b1}, \|x.\\{qqqq}&.\\{b2}, \|x.\\{qqqq}.%
\\{b3}\hskip-100pt
&\qquad\qquad\qquad(four quarterword fields)\cr}}$$
This is somewhat cumbersome to write, and not very readable either, but
macros will be used to make the notation shorter and more transparent.
The \PASCAL\ code below gives a formal definition of \\{memory\_word} and
its subsidiary types, using packed variant records. \TeX\ makes no
assumptions about the relative positions of the fields within a word.

Since we are assuming 32-bit integers, a halfword must contain at least
16 bits, and a quarterword must contain at least 8 bits.
But it doesn't hurt to have more bits; for example, with enough 36-bit
words you might be able to have \\{mem\_max} as large as 262142, which is
eight times as much memory as anybody had during the first four years of
\TeX's existence.

N.B.: Valuable memory space will be dreadfully wasted unless \TeX\ is compiled
by a \PASCAL\ that packs all of the \\{memory\_word} variants into
the space of a single integer. This means, for example, that \\{glue\_ratio}
words should be \\{short\_real} instead of \\{real} on some computers. Some
\PASCAL\ compilers will pack an integer whose subrange is `$0\to255$' into
an eight-bit field, but others insist on allocating space for an additional
sign bit; on such systems you can get 256 values into a quarterword only
if the subrange is `$-128\to127$'.

The present implementation tries to accommodate as many variations as possible,
so it makes rather general assumptions. If integers having the subrange
`$\\{min\_quarterword}\to\\{max\_quarterword}$' can be packed into a
quarterword,
and if integers having the subrange `$\\{min\_halfword}\to\\{max\_halfword}$'
can be packed into a halfword, everything should work satisfactorily.

It is usually most efficient to have $\\{min\_quarterword}=\\{min%
\_halfword}=0$,
so one should try to achieve this unless it causes a severe problem.
The values defined here are recommended for most 32-bit computers,
except \\{max\_halfword} is strange (just to make the test hairier).

\Y\P\D \37$\\{min\_quarterword}=0$\C{smallest allowable value in a %
\\{quarterword}}\par
\P\D \37$\\{max\_quarterword}=255$\C{largest allowable value in a %
\\{quarterword}}\par
\P\D \37$\\{min\_halfword}\S0$\C{smallest allowable value in a \\{halfword}}\par
\P\D \37$\\{max\_halfword}\S32768$\C{largest allowable value in a \\{halfword}}%
\par
\fi

\M111. Here are the inequalities that the quarterword and halfword values
must satisfy (or rather, the inequalities that they mustn't satisfy):

\Y\P$\4\X14:Check the ``constant'' values for consistency\X\mathrel{+}\S$\6
\&{init} \37\&{if} $(\\{mem\_min}\I\\{mem\_bot})\V(\\{mem\_max}\I\\{mem\_top})$
\1\&{then}\5
$\\{bad}\K10$;\ \2\6
\&{tini}\6
\&{if} $(\\{mem\_min}>\\{mem\_bot})\V(\\{mem\_max}<\\{mem\_top})$ \1\&{then}\5
$\\{bad}\K10$;\2\6
\&{if} $(\\{min\_quarterword}>0)\V(\\{max\_quarterword}<127)$ \1\&{then}\5
$\\{bad}\K11$;\2\6
\&{if} $(\\{min\_halfword}>0)\V(\\{max\_halfword}<32767)$ \1\&{then}\5
$\\{bad}\K12$;\2\6
\&{if} $(\\{min\_quarterword}<\\{min\_halfword})\V\30(\\{max\_quarterword}>%
\\{max\_halfword})$ \1\&{then}\5
$\\{bad}\K13$;\2\6
\&{if} $(\\{mem\_min}<\\{min\_halfword})\V(\\{mem\_max}\G\\{max\_halfword})\V%
\30(\\{mem\_bot}-\\{mem\_min}>\\{max\_halfword}+1)$ \1\&{then}\5
$\\{bad}\K14$;\2\6
\&{if} $(\\{font\_base}<\\{min\_quarterword})\V(\\{font\_max}>\\{max%
\_quarterword})$ \1\&{then}\5
$\\{bad}\K15$;\2\6
\&{if} $\\{font\_max}>\\{font\_base}+256$ \1\&{then}\5
$\\{bad}\K16$;\2\6
\&{if} $(\\{save\_size}>\\{max\_halfword})\V(\\{max\_strings}>\\{max%
\_halfword})$ \1\&{then}\5
$\\{bad}\K17$;\2\6
\&{if} $\\{buf\_size}>\\{max\_halfword}$ \1\&{then}\5
$\\{bad}\K18$;\2\6
\&{if} $\\{max\_quarterword}-\\{min\_quarterword}<255$ \1\&{then}\5
$\\{bad}\K19$;\2\par
\fi

\M112\*. The operation of adding or subtracting \\{min\_quarterword} occurs
quite
frequently in \TeX, so it is convenient to abbreviate this operation
by using the macros \\{qi} and \\{qo} for input and output to and from
quarterword format.

The inner loop of \TeX\ will run faster with respect to compilers
that don't optimize expressions like `$\|x+0$' and `$\|x-0$', if these
macros are simplified in the obvious way when $\\{min\_quarterword}=0$.
So they have been simplified here in the obvious way.

\Y\P\D \37$\\{qi}(\#)\S0+\#+0$\C{to put an \\{eight\_bits} item into a
quarterword}\par
\P\D \37$\\{qo}(\#)\S0+\#-0$\C{to take an \\{eight\_bits} item from a
quarterword}\par
\P\D \37$\\{hi}(\#)\S0+\#+0$\C{to put a sixteen-bit item into a halfword}\par
\P\D \37$\\{ho}(\#)\S0+\#-0$\C{to take a sixteen-bit item from a halfword}\par
\fi

\M113. The reader should study the following definitions closely:

\Y\P\D \37$\\{sc}\S\\{int}$\C{\\{scaled} data is equivalent to \\{integer}}\par
\Y\P$\4\X18:Types in the outer block\X\mathrel{+}\S$\6
$\\{quarterword}=\\{min\_quarterword}\to\\{max\_quarterword}$;\C{1/4 of a word}%
\6
$\\{halfword}=\\{min\_halfword}\to\\{max\_halfword}$;\C{1/2 of a word}\6
$\\{two\_choices}=1\to2$;\C{used when there are two variants in a record}\6
$\\{four\_choices}=1\to4$;\C{used when there are four variants in a record}\6
$\\{two\_halves}=$\1\5
\&{packed} \37\1\&{record} \37\\{rh}: \37\\{halfword};\2\6
\&{case} $\\{two\_choices}$ \1\&{of}\6
\41: \37$(\\{lh}:\\{halfword})$;\6
\42: \37$(\\{b0}:\\{quarterword};\,\35\\{b1}:\\{quarterword})$;\2\6
\&{end};\2\6
$\\{four\_quarters}=$\1\5
\&{packed} \37\1\&{record} \37\\{b0}: \37\\{quarterword};\6
\4\\{b1}: \37\\{quarterword};\6
\4\\{b2}: \37\\{quarterword};\6
\4\\{b3}: \37\\{quarterword};\2\6
\&{end};\2\6
$\\{memory\_word}=$\1\5
\1\&{record} \37\2\6
\&{case} $\\{four\_choices}$ \1\&{of}\6
\41: \37$(\\{int}:\\{integer})$;\6
\42: \37$(\\{gr}:\\{glue\_ratio})$;\6
\43: \37$(\\{hh}:\\{two\_halves})$;\6
\44: \37$(\\{qqqq}:\\{four\_quarters})$;\2\6
\&{end};\2\6
$\\{word\_file}=$\1\5
\&{file} \1\&{of}\5
\\{memory\_word};\2\2\par
\fi

\M114. When debugging, we may want to print a \\{memory\_word} without knowing
what type it is; so we print it in all modes.

\Y\P\&{debug} \37\&{procedure}\1\  \37$\\{print\_word}(\|w:\\{memory\_word})$;%
\C{prints \|w in all ways}\2\6
\&{begin} \37$\\{print\_int}(\|w.\\{int})$;\5
$\\{print\_char}(\.{"\ "})$;\6
$\\{print\_scaled}(\|w.\\{sc})$;\5
$\\{print\_char}(\.{"\ "})$;\6
$\\{print\_scaled}(\\{round}(\\{unity}\ast\\{float}(\|w.\\{gr})))$;\5
\\{print\_ln};\6
$\\{print\_int}(\|w.\\{hh}.\\{lh})$;\5
$\\{print\_char}(\.{"="})$;\5
$\\{print\_int}(\|w.\\{hh}.\\{b0})$;\5
$\\{print\_char}(\.{":"})$;\5
$\\{print\_int}(\|w.\\{hh}.\\{b1})$;\5
$\\{print\_char}(\.{";"})$;\5
$\\{print\_int}(\|w.\\{hh}.\\{rh})$;\5
$\\{print\_char}(\.{"\ "})$;\6
$\\{print\_int}(\|w.\\{qqqq}.\\{b0})$;\5
$\\{print\_char}(\.{":"})$;\5
$\\{print\_int}(\|w.\\{qqqq}.\\{b1})$;\5
$\\{print\_char}(\.{":"})$;\5
$\\{print\_int}(\|w.\\{qqqq}.\\{b2})$;\5
$\\{print\_char}(\.{":"})$;\5
$\\{print\_int}(\|w.\\{qqqq}.\\{b3})$;\6
\&{end};\6
\&{gubed}\par
\fi

\N115.  \[9] Dynamic memory allocation.
The \TeX\ system does nearly all of its own memory allocation, so that it
can readily be transported into environments that do not have automatic
facilities for strings, garbage collection, etc., and so that it can be in
control of what error messages the user receives. The dynamic storage
requirements of \TeX\ are handled by providing a large array \\{mem} in
which consecutive blocks of words are used as nodes by the \TeX\ routines.

Pointer variables are indices into this array, or into another array
called \\{eqtb} that will be explained later. A pointer variable might
also be a special flag that lies outside the bounds of \\{mem}, so we
allow pointers to assume any \\{halfword} value. The minimum halfword
value represents a null pointer. \TeX\ does not assume that $\\{mem}[\\{null}]$
exists.

\Y\P\D \37$\\{pointer}\S\\{halfword}$\C{a flag or a location in \\{mem} or %
\\{eqtb}}\par
\P\D \37$\\{null}\S\\{min\_halfword}$\C{the null pointer}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{temp\_ptr}: \37\\{pointer};\C{a pointer variable for occasional emergency
use}\par
\fi

\M116\*. The \\{mem} array is divided into two regions that are allocated
separately,
but the dividing line between these two regions is not fixed; they grow
together until finding their ``natural'' size in a particular job.
Locations less than or equal to \\{lo\_mem\_max} are used for storing
variable-length records consisting of two or more words each. This region
is maintained using an algorithm similar to the one described in exercise
2.5--19 of {\sl The Art of Computer Programming}. However, no size field
appears in the allocated nodes; the program is responsible for knowing the
relevant size when a node is freed. Locations greater than or equal to
\\{hi\_mem\_min} are used for storing one-word records; a conventional
\.{AVAIL} stack is used for allocation in this region.

Locations of \\{mem} between \\{mem\_bot} and \\{mem\_top} may be dumped as
part
of preloaded format files, by the \.{INITEX} preprocessor.
Production versions of \TeX\ may extend the memory at both ends in order to
provide more space; locations between \\{mem\_min} and \\{mem\_bot} are always
used for variable-size nodes, and locations between \\{mem\_top} and \\{mem%
\_max}
are always used for single-word nodes.

The key pointers that govern \\{mem} allocation have a prescribed order:
$$\hbox{$\\{null}\L\\{mem\_min}\L\\{mem\_bot}<\\{lo\_mem\_max}<\\{hi\_mem%
\_min}<\\{mem\_top}\L\\{mem\_end}\L\\{mem\_max}$.}$$

Empirical tests show that the present implementation of \TeX\ tends to
spend about 9\% of its running time allocating nodes, and about 6\%
deallocating them after their use.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{lo\_mem\_max}: \37\\{pointer};\C{the largest location of variable-size
memory in use}\6
\4\\{hi\_mem\_min}: \37\\{pointer};\C{the smallest location of one-word memory
in use}\par
\fi

\M117. In order to study the memory requirements of particular applications, it
is possible to prepare a version of \TeX\ that keeps track of current and
maximum memory usage. When code between the delimiters  \&{stat}  $\ldots$
  \&{tats}  is not ``commented out,'' \TeX\ will run a bit slower but it will
report these statistics when \\{tracing\_stats} is sufficiently large.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4$\\{var\_used},\39\\{dyn\_used}$: \37\\{integer};\C{how much memory is in
use}\par
\fi

\M118. Let's consider the one-word memory region first, since it's the
simplest. The pointer variable \\{mem\_end} holds the highest-numbered location
of \\{mem} that has ever been used. The free locations of \\{mem} that
occur between \\{hi\_mem\_min} and \\{mem\_end}, inclusive, are of type
\\{two\_halves}, and we write $\\{info}(\|p)$ and $\\{link}(\|p)$ for the %
\\{lh}
and \\{rh} fields of $\\{mem}[\|p]$ when it is of this type. The single-word
free locations form a linked list
$$\\{avail},\;\hbox{$\\{link}(\\{avail})$},\;\hbox{$\\{link}(\\{link}(%
\\{avail}))$},\;\ldots$$
terminated by \\{null}.

\Y\P\D \37$\\{link}(\#)\S\\{mem}[\#].\\{hh}.\\{rh}$\C{the \\{link} field of a
memory word}\par
\P\D \37$\\{info}(\#)\S\\{mem}[\#].\\{hh}.\\{lh}$\C{the \\{info} field of a
memory word}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{avail}: \37\\{pointer};\C{head of the list of available one-word nodes}\6
\4\\{mem\_end}: \37\\{pointer};\C{the last one-word node used in \\{mem}}\par
\fi

\M119. If memory is exhausted, it might mean that the user has forgotten
a right brace. We will define some procedures later that try to help
pinpoint the trouble.

\Y\P\X292:Declare the procedure called \\{show\_token\_list}\X\6
\X306:Declare the procedure called \\{runaway}\X\par
\fi

\M120. The function \\{get\_avail} returns a pointer to a new one-word node
whose
\\{link} field is null. However, \TeX\ will halt if there is no more room left.

If the available-space list is empty, i.e., if $\\{avail}=\\{null}$,
we try first to increase \\{mem\_end}. If that cannot be done, i.e., if
$\\{mem\_end}=\\{mem\_max}$, we try to decrease \\{hi\_mem\_min}. If that
cannot be
done, i.e., if $\\{hi\_mem\_min}=\\{low\_mem\_max}+1$, we have to quit.

\Y\P\4\&{function}\1\  \37\\{get\_avail}: \37\\{pointer};\C{single-word node
allocation}\6
\4\&{var} \37\|p: \37\\{pointer};\C{the new node being got}\2\6
\&{begin} \37$\|p\K\\{avail}$;\C{get top location in the \\{avail} stack}\6
\&{if} $\|p\I\\{null}$ \1\&{then}\5
$\\{avail}\K\\{link}(\\{avail})$\C{and pop it off}\6
\4\&{else} \&{if} $\\{mem\_end}<\\{mem\_max}$ \1\&{then}\C{or go into virgin
territory}\6
\&{begin} \37$\\{incr}(\\{mem\_end})$;\5
$\|p\K\\{mem\_end}$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{decr}(\\{hi\_mem\_min})$;\5
$\|p\K\\{hi\_mem\_min}$;\6
\&{if} $\\{hi\_mem\_min}\L\\{lo\_mem\_max}$ \1\&{then}\6
\&{begin} \37\\{runaway};\C{if memory is exhausted, display possible runaway
text}\6
$\\{overflow}(\.{"main\ memory\ size"},\39\\{mem\_max}+1-\\{mem\_min})$;%
\C{quit; all one-word nodes are busy}\6
\&{end};\2\6
\&{end};\2\2\6
$\\{link}(\|p)\K\\{null}$;\C{provide an oft-desired initialization of the new
node}\6
\&{stat} \37$\\{incr}(\\{dyn\_used})$;\ \&{tats}\C{maintain statistics}\6
$\\{get\_avail}\K\|p$;\6
\&{end};\par
\fi

\M121. Conversely, a one-word node is recycled by calling \\{free\_avail}.
This routine is part of \TeX's ``inner loop,'' so we want it to be fast.

\Y\P\D \37$\\{free\_avail}(\#)\S$\C{single-word node liberation}\6
\&{begin} \37$\\{link}(\#)\K\\{avail}$;\5
$\\{avail}\K\#$;\6
\&{stat} \37$\\{decr}(\\{dyn\_used})$;\ \&{tats}\6
\&{end}\par
\fi

\M122. There's also a \\{fast\_get\_avail} routine, which saves the
procedure-call
overhead at the expense of extra programming. This routine is used in
the places that would otherwise account for the most calls of \\{get\_avail}.

\Y\P\D \37$\\{fast\_get\_avail}(\#)\S\hbox{}$\6
\&{begin} \37$\#\K\\{avail}$;\C{avoid \\{get\_avail} if possible, to save time}%
\6
\&{if} $\#=\\{null}$ \1\&{then}\5
$\#\K\\{get\_avail}$\6
\4\&{else} \&{begin} \37$\\{avail}\K\\{link}(\#)$;\5
$\\{link}(\#)\K\\{null}$;\6
\&{stat} \37$\\{incr}(\\{dyn\_used})$;\ \&{tats}\6
\&{end};\2\6
\&{end}\par
\fi

\M123. The procedure $\\{flush\_list}(\|p)$ frees an entire linked list of
one-word nodes that starts at position \|p.

\Y\P\4\&{procedure}\1\  \37$\\{flush\_list}(\|p:\\{pointer})$;\C{makes list of
single-word nodes 	available}\6
\4\&{var} \37$\|q,\39\|r$: \37\\{pointer};\C{list traversers}\2\6
\&{begin} \37\&{if} $\|p\I\\{null}$ \1\&{then}\6
\&{begin} \37$\|r\K\|p$;\6
\1\&{repeat} \37$\|q\K\|r$;\5
$\|r\K\\{link}(\|r)$;\6
\&{stat} \37$\\{decr}(\\{dyn\_used})$;\ \&{tats}\6
\4\&{until}\5
$\|r=\\{null}$;\C{now \|q is the last node on the list}\2\6
$\\{link}(\|q)\K\\{avail}$;\5
$\\{avail}\K\|p$;\6
\&{end};\2\6
\&{end};\par
\fi

\M124. The available-space list that keeps track of the variable-size portion
of \\{mem} is a nonempty, doubly-linked circular list of empty nodes,
pointed to by the roving pointer \\{rover}.

Each empty node has size 2 or more; the first word contains the special
value \\{max\_halfword} in its \\{link} field and the size in its \\{info}
field;
the second word contains the two pointers for double linking.

Each nonempty node also has size 2 or more. Its first word is of type
\\{two\_halves}\kern-1pt, and its \\{link} field is never equal to \\{max%
\_halfword}.
Otherwise there is complete flexibility with respect to the contents
of its other fields and its other words.

(We require $\\{mem\_max}<\\{max\_halfword}$ because terrible things can happen
when \\{max\_halfword} appears in the \\{link} field of a nonempty node.)

\Y\P\D \37$\\{empty\_flag}\S\\{max\_halfword}$\C{the \\{link} of an empty
variable-size node}\par
\P\D \37$\\{is\_empty}(\#)\S(\\{link}(\#)=\\{empty\_flag})$\C{tests for empty
node}\par
\P\D \37$\\{node\_size}\S\\{info}$\C{the size field in empty variable-size
nodes}\par
\P\D \37$\\{llink}(\#)\S\\{info}(\#+1)$\C{left link in doubly-linked list of
empty nodes}\par
\P\D \37$\\{rlink}(\#)\S\\{link}(\#+1)$\C{right link in doubly-linked list of
empty nodes}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{rover}: \37\\{pointer};\C{points to some node in the list of empties}\par
\fi

\M125. A call to \\{get\_node} with argument \|s returns a pointer to a new
node
of size~\|s, which must be 2~or more. The \\{link} field of the first word
of this new node is set to null. An overflow stop occurs if no suitable
space exists.

If \\{get\_node} is called with $s=2↑{30}$, it simply merges adjacent free
areas and returns the value \\{max\_halfword}.

\Y\P\4\&{function}\1\  \37$\\{get\_node}(\|s:\\{integer})$: \37\\{pointer};%
\C{variable-size node allocation}\6
\4\&{label} \37$\\{found},\39\\{exit},\39\\{restart}$;\6
\4\&{var} \37\|p: \37\\{pointer};\C{the node currently under inspection}\6
\|q: \37\\{pointer};\C{the node physically after node \|p}\6
\|r: \37\\{integer};\C{the newly allocated node, or a candidate for this honor}%
\6
\|t: \37\\{integer};\C{temporary register}\2\6
\&{begin} \37\\{restart}: \37$\|p\K\\{rover}$;\C{start at some free node in the
ring}\6
\1\&{repeat} \37\X127:Try to allocate within node \|p and its physical
successors, and \&{goto} \\{found} if allocation was possible\X;\6
$\|p\K\\{rlink}(\|p)$;\C{move to the next node in the ring}\6
\4\&{until}\5
$\|p=\\{rover}$;\C{repeat until the whole list has been traversed}\2\6
\&{if} $\|s=\O{10000000000}$ \1\&{then}\6
\&{begin} \37$\\{get\_node}\K\\{max\_halfword}$;\5
\&{return};\6
\&{end};\2\6
\&{if} $\\{lo\_mem\_max}+2<\\{hi\_mem\_min}$ \1\&{then}\6
\&{if} $\\{lo\_mem\_max}+2\L\\{mem\_bot}+\\{max\_halfword}$ \1\&{then}\5
\X126:Grow more variable-size memory and \&{goto} \\{restart}\X;\2\2\6
$\\{overflow}(\.{"main\ memory\ size"},\39\\{mem\_max}+1-\\{mem\_min})$;%
\C{sorry, nothing satisfactory is left}\6
\4\\{found}: \37$\\{link}(\|r)\K\\{null}$;\C{this node is now nonempty}\6
\&{stat} \37$\\{var\_used}\K\\{var\_used}+\|s$;\C{maintain usage statistics}\6
\&{tats}\6
$\\{get\_node}\K\|r$;\6
\4\\{exit}: \37\&{end};\par
\fi

\M126. The lower part of \\{mem} grows by 1000 words at a time, unless
we are very close to going under. When it grows, we simply link
a new node into the available-space list. This method of controlled
growth helps to keep the \\{mem} usage consecutive when \TeX\ is
implemented on ``virtual memory'' systems.

\Y\P$\4\X126:Grow more variable-size memory and \&{goto} \\{restart}\X\S$\6
\&{begin} \37\&{if} $\\{lo\_mem\_max}+1000<\\{hi\_mem\_min}$ \1\&{then}\5
$\|t\K\\{lo\_mem\_max}+1000$\6
\4\&{else} $\|t\K(\\{lo\_mem\_max}+\\{hi\_mem\_min}+2)\mathbin{\&{div}}2$;\C{$%
\\{lo\_mem\_max}+2\L\|t<\\{hi\_mem\_min}$}\2\6
$\|p\K\\{llink}(\\{rover})$;\5
$\|q\K\\{lo\_mem\_max}$;\5
$\\{rlink}(\|p)\K\|q$;\5
$\\{llink}(\\{rover})\K\|q$;\6
\&{if} $\|t>\\{mem\_bot}+\\{max\_halfword}$ \1\&{then}\5
$\|t\K\\{mem\_bot}+\\{max\_halfword}$;\2\6
$\\{rlink}(\|q)\K\\{rover}$;\5
$\\{llink}(\|q)\K\|p$;\5
$\\{link}(\|q)\K\\{empty\_flag}$;\5
$\\{node\_size}(\|q)\K\|t-\\{lo\_mem\_max}$;\6
$\\{lo\_mem\_max}\K\|t$;\5
$\\{link}(\\{lo\_mem\_max})\K\\{null}$;\5
$\\{info}(\\{lo\_mem\_max})\K\\{null}$;\5
$\\{rover}\K\|q$;\5
\&{goto} \37\\{restart};\6
\&{end}\par
\U section~125.\fi

\M127. Empirical tests show that the routine in this section performs a
node-merging operation about 0.75 times per allocation, on the average,
after which it finds that $\|r>\|p+1$ about 95\% of the time.

\Y\P$\4\X127:Try to allocate within node \|p and its physical successors, and %
\&{goto} \\{found} if allocation was possible\X\S$\6
$\|q\K\|p+\\{node\_size}(\|p)$;\C{find the physical successor}\6
\&{while} $\\{is\_empty}(\|q)$ \1\&{do}\C{merge node \|p with node \|q}\6
\&{begin} \37$\|t\K\\{rlink}(\|q)$;\6
\&{if} $\|q=\\{rover}$ \1\&{then}\5
$\\{rover}\K\|t$;\2\6
$\\{llink}(\|t)\K\\{llink}(\|q)$;\5
$\\{rlink}(\\{llink}(\|q))\K\|t$;\6
$\|q\K\|q+\\{node\_size}(\|q)$;\6
\&{end};\2\6
$\|r\K\|q-\|s$;\6
\&{if} $\|r>\|p+1$ \1\&{then}\5
\X128:Allocate from the top of node \|p and \&{goto} \\{found}\X;\2\6
\&{if} $\|r=\|p$ \1\&{then}\6
\&{if} $\\{rlink}(\|p)\I\|p$ \1\&{then}\5
\X129:Allocate entire node \|p and \&{goto} \\{found}\X;\2\2\6
$\\{node\_size}(\|p)\K\|q-\|p$\C{reset the size in case it grew}\par
\U section~125.\fi

\M128. \P$\X128:Allocate from the top of node \|p and \&{goto} \\{found}\X\S$\6
\&{begin} \37$\\{node\_size}(\|p)\K\|r-\|p$;\C{store the remaining size}\6
$\\{rover}\K\|p$;\C{start searching here next time}\6
\&{goto} \37\\{found};\6
\&{end}\par
\U section~127.\fi

\M129. Here we delete node \|p from the ring, and let \\{rover} rove around.

\Y\P$\4\X129:Allocate entire node \|p and \&{goto} \\{found}\X\S$\6
\&{begin} \37$\\{rover}\K\\{rlink}(\|p)$;\5
$\|t\K\\{llink}(\|p)$;\5
$\\{llink}(\\{rover})\K\|t$;\5
$\\{rlink}(\|t)\K\\{rover}$;\5
\&{goto} \37\\{found};\6
\&{end}\par
\U section~127.\fi

\M130. Conversely, when some variable-size node \|p of size \|s is no longer
needed,
the operation $\\{free\_node}(\|p,\|s)$ will make its words available, by
inserting
\|p as a new empty node just before where \\{rover} now points.

\Y\P\4\&{procedure}\1\  \37$\\{free\_node}(\|p:\\{pointer};\,\35\|s:%
\\{halfword})$;\C{variable-size node 	liberation}\6
\4\&{var} \37\|q: \37\\{pointer};\C{$\\{llink}(\\{rover})$}\2\6
\&{begin} \37$\\{node\_size}(\|p)\K\|s$;\5
$\\{link}(\|p)\K\\{empty\_flag}$;\5
$\|q\K\\{llink}(\\{rover})$;\5
$\\{llink}(\|p)\K\|q$;\5
$\\{rlink}(\|p)\K\\{rover}$;\C{set both links}\6
$\\{llink}(\\{rover})\K\|p$;\5
$\\{rlink}(\|q)\K\|p$;\C{insert \|p into the ring}\6
\&{stat} \37$\\{var\_used}\K\\{var\_used}-\|s$;\ \&{tats}\C{maintain
statistics}\6
\&{end};\par
\fi

\M131. Just before \.{INITEX} writes out the memory, it sorts the doubly linked
available space list. The list is probably very short at such times, so a
simple insertion sort is used. The smallest available location will be
pointed to by \\{rover}, the next-smallest by $\\{rlink}(\\{rover})$, etc.

\Y\P\&{init} \37\&{procedure}\1\  \37\\{sort\_avail};\C{sorts the available
variable-size nodes 	by location}\6
\4\&{var} \37$\|p,\39\|q,\39\|r$: \37\\{pointer};\C{indices into \\{mem}}\6
\\{old\_rover}: \37\\{pointer};\C{initial \\{rover} setting}\2\6
\&{begin} \37$\|p\K\\{get\_node}(\O{10000000000})$;\C{merge adjacent free
areas}\6
$\|p\K\\{rlink}(\\{rover})$;\5
$\\{rlink}(\\{rover})\K\\{max\_halfword}$;\5
$\\{old\_rover}\K\\{rover}$;\6
\&{while} $\|p\I\\{old\_rover}$ \1\&{do}\5
\X132:Sort \|p into the list starting at \\{rover} and advance \|p to $%
\\{rlink}(\|p)$\X;\2\6
$\|p\K\\{rover}$;\6
\&{while} $\\{rlink}(\|p)\I\\{max\_halfword}$ \1\&{do}\6
\&{begin} \37$\\{llink}(\\{rlink}(\|p))\K\|p$;\5
$\|p\K\\{rlink}(\|p)$;\6
\&{end};\2\6
$\\{rlink}(\|p)\K\\{rover}$;\5
$\\{llink}(\\{rover})\K\|p$;\6
\&{end};\6
\&{tini}\par
\fi

\M132. The following  \&{while}  loop terminates, since the list that starts at
\\{rover} ends with \\{max\_halfword} during the sorting procedure.

\Y\P$\4\X132:Sort \|p into the list starting at \\{rover} and advance \|p to $%
\\{rlink}(\|p)$\X\S$\6
\&{if} $\|p<\\{rover}$ \1\&{then}\6
\&{begin} \37$\|q\K\|p$;\5
$\|p\K\\{rlink}(\|q)$;\5
$\\{rlink}(\|q)\K\\{rover}$;\5
$\\{rover}\K\|q$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\|q\K\\{rover}$;\6
\&{while} $\\{rlink}(\|q)<\|p$ \1\&{do}\5
$\|q\K\\{rlink}(\|q)$;\2\6
$\|r\K\\{rlink}(\|p)$;\5
$\\{rlink}(\|p)\K\\{rlink}(\|q)$;\5
$\\{rlink}(\|q)\K\|p$;\5
$\|p\K\|r$;\6
\&{end}\2\par
\U section~131.\fi

\N133.  \[10] Data structures for boxes and their friends.
From the computer's standpoint, \TeX's chief mission is to create
horizontal and vertical lists. We shall now investigate how the elements
of these lists are represented internally as nodes in the dynamic memory.

A horizontal or vertical list is linked together by \\{link} fields in
the first word of each node. Individual nodes represent boxes, glue,
penalties, or special things like discretionary hyphens; because of this
variety, some nodes are longer than others, and we must distinguish different
kinds of nodes. We do this by putting a `\\{type}' field in the first word,
together with the link and an optional `\\{subtype}'.

\Y\P\D \37$\\{type}(\#)\S\\{mem}[\#].\\{hh}.\\{b0}$\C{identifies what kind of
node this is}\par
\P\D \37$\\{subtype}(\#)\S\\{mem}[\#].\\{hh}.\\{b1}$\C{secondary identification
in some cases}\par
\fi

\M134\*. A \\{char\_node}, which represents a single character, is the most
important
kind of node because it accounts for the vast majority of all boxes.
Special precautions are therefore taken to ensure that a \\{char\_node} does
not take up much memory space. Every such node is one word long, and in fact
it is identifiable by this property, since other kinds of nodes have at least
two words, and they appear in \\{mem} locations less than \\{hi\_mem\_min}.
This makes it possible to omit the \\{type} field in a \\{char\_node}, leaving
us room for two bytes that identify a \\{font} and a \\{character} within
that font.

Note that the format of a \\{char\_node} allows for up to 256 different
fonts and up to 256 characters per font; but most implementations will
probably limit the total number of fonts to fewer than 75 per job,
and most fonts will stick to characters less than 128 (since higher codes
are accessed outside of math mode only via ligatures and the \.{\\char}
operator).

Extensions of \TeX\ intended for oriental languages will need even more
than $256\times256$ possible characters, when we consider different sizes
and styles of type.  It is suggested that Chinese and Japanese fonts be
handled by representing such characters in two consecutive \\{char\_node}
entries: The first of these has $\\{font}=\\{font\_base}$ and links to the
second,
while the second identifies the font and the character dimensions.
The saving feature about oriental characters is that most of them have
the same box dimensions. The \\{character} field of the first \\{char\_node}
is an ``extension'' that distinguishes between graphic symbols whose
dimensions are identical for typesetting purposes. Such an extension of
\TeX\ would not be difficult; further details are left to the reader.

In order to make sure that the \\{character} code fits in a quarterword,
\TeX\ adds the quantity \\{min\_quarterword} to the actual code.

Character nodes appear only in horizontal lists, never in vertical lists.

\Y\P\D \37$\\{is\_char\_node}(\#)\S(\#\G\\{hi\_mem\_min})$\C{does the argument
point to a \\{char\_node}?}\par
\P\D \37$\\{font}\S\\{type}$\C{the font code in a \\{char\_node}}\par
\P\D \37$\\{character}\S\\{subtype}$\C{the character code in a \\{char\_node}}%
\par
\P\D \37$\\{is\_xchar\_node}(\#)\S(\\{font}(\#)=\\{font\_base})$\C{is this %
\\{char\_node} extended?}\par
\P\D \37$\\{bypass\_xchar}(\#)\S$\1\6
\&{if} $\\{is\_xchar\_node}(\#)$ \1\&{then}\5
$\#\K\\{link}(\#)$\2\2\par
\fi

\M135. An \\{hlist\_node} stands for a box that was made from a horizontal
list.
Each \\{hlist\_node} is seven words long, and contains the following fields
(in addition to the mandatory \\{type} and \\{link}, which we shall not
mention explicitly when discussing the other node types): The \\{height} and
\\{width} and \\{depth} are scaled integers denoting the dimensions of the
box.  There is also a \\{shift\_amount} field, a scaled integer indicating
how much this box should be lowered (if it appears in a horizontal list),
or how much it should be moved to the right (if it appears in a vertical
list). There is a \\{list\_ptr} field, which points to the beginning of the
list from which this box was fabricated; if \\{list\_ptr} is \\{null}, the box
is empty. Finally, there are three fields that represent the setting of
the glue:  $\\{glue\_set}(\|p)$ is a word of type \\{glue\_ratio} that
represents
the proportionality constant for glue setting; $\\{glue\_sign}(\|p)$ is
\\{stretching} or \\{shrinking} or \\{normal} depending on whether or not the
glue should stretch or shrink or remain rigid; and $\\{glue\_order}(\|p)$
specifies the order of infinity to which glue setting applies (\\{normal},
\\{fil}, \\{fill}, or \\{filll}). The \\{subtype} field is not used.

\Y\P\D \37$\\{hlist\_node}=0$\C{\\{type} of hlist nodes}\par
\P\D \37$\\{box\_node\_size}=7$\C{number of words to allocate for a box node}%
\par
\P\D \37$\\{width\_offset}=1$\C{position of \\{width} field in a box node}\par
\P\D \37$\\{depth\_offset}=2$\C{position of \\{depth} field in a box node}\par
\P\D \37$\\{height\_offset}=3$\C{position of \\{height} field in a box node}\par
\P\D \37$\\{width}(\#)\S\\{mem}[\#+\\{width\_offset}].\\{sc}$\C{width of the
box, in sp}\par
\P\D \37$\\{depth}(\#)\S\\{mem}[\#+\\{depth\_offset}].\\{sc}$\C{depth of the
box, in sp}\par
\P\D \37$\\{height}(\#)\S\\{mem}[\#+\\{height\_offset}].\\{sc}$\C{height of the
box, in sp}\par
\P\D \37$\\{shift\_amount}(\#)\S\\{mem}[\#+4].\\{sc}$\C{repositioning distance,
in sp}\par
\P\D \37$\\{list\_offset}=5$\C{position of \\{list\_ptr} field in a box node}%
\par
\P\D \37$\\{list\_ptr}(\#)\S\\{link}(\#+\\{list\_offset})$\C{beginning of the
list inside the box}\par
\P\D \37$\\{glue\_order}(\#)\S\\{subtype}(\#+\\{list\_offset})$\C{applicable
order of infinity}\par
\P\D \37$\\{glue\_sign}(\#)\S\\{type}(\#+\\{list\_offset})$\C{stretching or
shrinking}\par
\P\D \37$\\{normal}=0$\C{the most common case when several cases are named}\par
\P\D \37$\\{stretching}=1$\C{glue setting applies to the stretch components}\par
\P\D \37$\\{shrinking}=2$\C{glue setting applies to the shrink components}\par
\P\D \37$\\{glue\_offset}=6$\C{position of \\{glue\_set} in a box node}\par
\P\D \37$\\{glue\_set}(\#)\S\\{mem}[\#+\\{glue\_offset}].\\{gr}$\C{a word of
type \\{glue\_ratio} for glue setting}\par
\fi

\M136. The \\{new\_null\_box} function returns a pointer to an \\{hlist\_node}
in
which all subfields have the values corresponding to `\.{\\hbox\{\}}'.
The \\{subtype} field is set to \\{min\_quarterword}, since that's the desired
\\{span\_count} value if this \\{hlist\_node} is changed to an \\{unset\_node}.

\Y\P\4\&{function}\1\  \37\\{new\_null\_box}: \37\\{pointer};\C{creates a new
box node}\6
\4\&{var} \37\|p: \37\\{pointer};\C{the new node}\2\6
\&{begin} \37$\|p\K\\{get\_node}(\\{box\_node\_size})$;\5
$\\{type}(\|p)\K\\{hlist\_node}$;\5
$\\{subtype}(\|p)\K\\{min\_quarterword}$;\5
$\\{width}(\|p)\K0$;\5
$\\{depth}(\|p)\K0$;\5
$\\{height}(\|p)\K0$;\5
$\\{shift\_amount}(\|p)\K0$;\5
$\\{list\_ptr}(\|p)\K\\{null}$;\5
$\\{glue\_sign}(\|p)\K\\{normal}$;\5
$\\{glue\_order}(\|p)\K\\{normal}$;\5
$\\{set\_glue\_ratio\_zero}(\\{glue\_set}(\|p))$;\5
$\\{new\_null\_box}\K\|p$;\6
\&{end};\par
\fi

\M137. A \\{vlist\_node} is like an \\{hlist\_node} in all respects except that
it
was made from a vertical list.

\Y\P\D \37$\\{vlist\_node}=1$\C{\\{type} of vlist nodes}\par
\fi

\M138. A \\{rule\_node} stands for a solid black rectangle; it has \\{width},
\\{depth}, and \\{height} fields just as in an \\{hlist\_node}. However, if
any of these dimensions is $-2↑{30}$, the actual value will be determined
by running the rule up to the boundary of the innermost enclosing box.
This is called a ``running dimension.'' The \\{width} is never running in
an hlist; the \\{height} and \\{depth} are never running in a vlist.

\Y\P\D \37$\\{rule\_node}=2$\C{\\{type} of rule nodes}\par
\P\D \37$\\{rule\_node\_size}=4$\C{number of words to allocate for a rule node}%
\par
\P\D \37$\\{null\_flag}\S-\O{10000000000}$\C{$-2↑{30}$, signifies a missing
item}\par
\P\D \37$\\{is\_running}(\#)\S(\#=\\{null\_flag})$\C{tests for a running
dimension}\par
\fi

\M139. A new rule node is delivered by the \\{new\_rule} function. It
makes all the dimensions ``running,'' so you have to change the
ones that are not allowed to run.

\Y\P\4\&{function}\1\  \37\\{new\_rule}: \37\\{pointer};\6
\4\&{var} \37\|p: \37\\{pointer};\C{the new node}\2\6
\&{begin} \37$\|p\K\\{get\_node}(\\{rule\_node\_size})$;\5
$\\{type}(\|p)\K\\{rule\_node}$;\5
$\\{subtype}(\|p)\K0$;\C{the \\{subtype} is not used}\6
$\\{width}(\|p)\K\\{null\_flag}$;\5
$\\{depth}(\|p)\K\\{null\_flag}$;\5
$\\{height}(\|p)\K\\{null\_flag}$;\5
$\\{new\_rule}\K\|p$;\6
\&{end};\par
\fi

\M140. Insertions are represented by \\{ins\_node} records, where the %
\\{subtype}
indicates the corresponding box number. For example, `\.{\\insert 250}'
leads to an \\{ins\_node} whose \\{subtype} is $250+\\{min\_quarterword}$.
The \\{height} field of an \\{ins\_node} is slightly misnamed; it actually
holds
the natural height plus depth of the vertical list being inserted.
The \\{depth} field holds the \\{split\_max\_depth} to be used in case this
insertion is split, and the \\{split\_top\_ptr} points to the corresponding
\\{split\_top\_skip}. The \\{float\_cost} field holds the \\{floating\_penalty}
that
will be used if this insertion floats to a subsequent page after a
split insertion of the same class.  There is one more field, the
\\{ins\_ptr}, which points to the beginning of the vlist for the insertion.

\Y\P\D \37$\\{ins\_node}=3$\C{\\{type} of insertion nodes}\par
\P\D \37$\\{ins\_node\_size}=5$\C{number of words to allocate for an insertion}%
\par
\P\D \37$\\{float\_cost}(\#)\S\\{mem}[\#+1].\\{int}$\C{the \\{floating%
\_penalty} to be used}\par
\P\D \37$\\{ins\_ptr}(\#)\S\\{info}(\#+4)$\C{the vertical list to be inserted}%
\par
\P\D \37$\\{split\_top\_ptr}(\#)\S\\{link}(\#+4)$\C{the \\{split\_top\_skip} to
be used}\par
\fi

\M141. A \\{mark\_node} has a \\{mark\_ptr} field that points to the reference
count
of a token list that contains the user's \.{\\mark} text.
This field occupies a full word instead of a halfword, because
there's nothing to put in the other halfword; it is easier in \PASCAL\ to
use the full word than to risk leaving garbage in the unused half.

\Y\P\D \37$\\{mark\_node}=4$\C{\\{type} of a mark node}\par
\P\D \37$\\{small\_node\_size}=2$\C{number of words to allocate for most node
types}\par
\P\D \37$\\{mark\_ptr}(\#)\S\\{mem}[\#+1].\\{int}$\C{head of the token list for
a mark}\par
\fi

\M142. An \\{adjust\_node}, which occurs only in horizontal lists,
specifies material that will be moved out into the surrounding
vertical list; i.e., it is used to implement \TeX's `\.{\\vadjust}'
operation.  The \\{adjust\_ptr} field points to the vlist containing this
material.

\Y\P\D \37$\\{adjust\_node}=5$\C{\\{type} of an adjust node}\par
\P\D \37$\\{adjust\_ptr}\S\\{mark\_ptr}$\C{vertical list to be moved out of
horizontal list}\par
\fi

\M143. A \\{ligature\_node}, which occurs only in horizontal lists, specifies a
composite character that was formed from two or more actual characters.
The second word of the node, which is called the \\{lig\_char} word, contains
\\{font} and \\{character} fields just as in a \\{char\_node}. The characters
that generated the ligature have not been forgotten, since they are needed
for diagnostic messages and for hyphenation; the \\{lig\_ptr} field points to
a linked list of character nodes for those characters.

\Y\P\D \37$\\{ligature\_node}=6$\C{\\{type} of a ligature node}\par
\P\D \37$\\{lig\_char}(\#)\S\#+1$\C{the word where the ligature is to be found}%
\par
\P\D \37$\\{lig\_ptr}(\#)\S\\{link}(\\{lig\_char}(\#))$\C{the list of
characters}\par
\fi

\M144. The \\{new\_ligature} function creates a ligature node having given
contents of the \\{font}, \\{character}, and \\{lig\_ptr} fields.

\Y\P\4\&{function}\1\  \37$\\{new\_ligature}(\|f,\39\|c:\\{quarterword};\,\35%
\|q:\\{pointer})$: \37\\{pointer};\6
\4\&{var} \37\|p: \37\\{pointer};\C{the new node}\2\6
\&{begin} \37$\|p\K\\{get\_node}(\\{small\_node\_size})$;\5
$\\{type}(\|p)\K\\{ligature\_node}$;\5
$\\{subtype}(\|p)\K0$;\C{the \\{subtype} is not used}\6
$\\{font}(\\{lig\_char}(\|p))\K\|f$;\5
$\\{character}(\\{lig\_char}(\|p))\K\|c$;\5
$\\{lig\_ptr}(\|p)\K\|q$;\5
$\\{new\_ligature}\K\|p$;\6
\&{end};\par
\fi

\M145. A \\{disc\_node}, which occurs only in horizontal lists, specifies a
``dis\-cretion\-ary'' line break. If such a break occurs at node \|p, the text
that starts at $\\{pre\_break}(\|p)$ will precede the break, the text that
starts at
$\\{post\_break}(\|p)$ will follow the break, and text that appears in the next
$\\{replace\_count}(\|p)$ nodes will be ignored. For example, an ordinary
discretionary hyphen, indicated by `\.{\\-}', yields a \\{disc\_node} with
\\{pre\_break} pointing to a \\{char\_node} containing a hyphen, $\\{post%
\_break}=\\{null}$,
and $\\{replace\_count}=0$. All three of the discretionary texts must be
lists that consist entirely of character, kern, box, rule, and ligature nodes.

If $\\{pre\_break}(\|p)=\\{null}$, the \\{ex\_hyphen\_penalty} will be charged
for this
break.  Otherwise the \\{hyphen\_penalty} will be charged.  The texts will
actually be substituted into the list by the line-breaking algorithm if it
decides to make the break, and the discretionary node will disappear at
that time; thus, the output routine sees only discretionaries that were
not chosen.

\Y\P\D \37$\\{disc\_node}=7$\C{\\{type} of a discretionary node}\par
\P\D \37$\\{replace\_count}\S\\{subtype}$\C{how many subsequent nodes to
replace}\par
\P\D \37$\\{pre\_break}\S\\{llink}$\C{text that precedes a discretionary break}%
\par
\P\D \37$\\{post\_break}\S\\{rlink}$\C{text that follows a discretionary break}%
\par
\Y\P\4\&{function}\1\  \37\\{new\_disc}: \37\\{pointer};\C{creates an empty %
\\{disc\_node}}\6
\4\&{var} \37\|p: \37\\{pointer};\C{the new node}\2\6
\&{begin} \37$\|p\K\\{get\_node}(\\{small\_node\_size})$;\5
$\\{type}(\|p)\K\\{disc\_node}$;\5
$\\{replace\_count}(\|p)\K0$;\5
$\\{pre\_break}(\|p)\K\\{null}$;\5
$\\{post\_break}(\|p)\K\\{null}$;\5
$\\{new\_disc}\K\|p$;\6
\&{end};\par
\fi

\M146. A \\{whatsit\_node} is a wild card reserved for extensions to \TeX. The
\\{subtype} field in its first word says what `\\{whatsit}' it is, and
implicitly determines the node size (which must be 2 or more) and the
format of the remaining words. When a \\{whatsit\_node} is encountered
in a list, special actions are invoked; knowledgeable people who are
careful not to mess up the rest of \TeX\ are able to make \TeX\ do new
things by adding code at the end of the program. For example, there
might be a `\TeX nicolor' extension to specify different colors of ink,
and the whatsit node might contain the desired parameters.

The present implementation of \TeX\ treats the features associated with
`\.{\\write}' and `\.{\\special}' as if they were extensions, in order to
illustrate how such routines might be coded. We shall defer further
discussion of extensions until the end of this program.

\Y\P\D \37$\\{whatsit\_node}=8$\C{\\{type} of special extension nodes}\par
\fi

\M147. A \\{math\_node}, which occurs only in horizontal lists, appears before
and
after mathematical formulas. The \\{subtype} field is \\{before} before the
formula and \\{after} after it. There is a \\{width} field, which represents
the amount of surrounding space inserted by \.{\\mathsurround}.

\Y\P\D \37$\\{math\_node}=9$\C{\\{type} of a math node}\par
\P\D \37$\\{before}=0$\C{\\{subtype} for math node that introduces a formula}%
\par
\P\D \37$\\{after}=1$\C{\\{subtype} for math node that winds up a formula}\par
\Y\P\4\&{function}\1\  \37$\\{new\_math}(\|w:\\{scaled};\,\35\|s:\\{small%
\_number})$: \37\\{pointer};\6
\4\&{var} \37\|p: \37\\{pointer};\C{the new node}\2\6
\&{begin} \37$\|p\K\\{get\_node}(\\{small\_node\_size})$;\5
$\\{type}(\|p)\K\\{math\_node}$;\5
$\\{subtype}(\|p)\K\|s$;\5
$\\{width}(\|p)\K\|w$;\5
$\\{new\_math}\K\|p$;\6
\&{end};\par
\fi

\M148. \TeX\ makes use of the fact that \\{hlist\_node}, \\{vlist\_node},
\\{rule\_node}, \\{ins\_node}, \\{mark\_node}, \\{adjust\_node}, \\{ligature%
\_node},
\\{disc\_node}, \\{whatsit\_node}, and \\{math\_node} are at the low end of the
type codes, by permitting a break at glue in a list if and only if the
\\{type} of the previous node is less than \\{math\_node}. Furthermore, a
node is discarded after a break if its type is \\{math\_node} or more.

\Y\P\D \37$\\{precedes\_break}(\#)\S(\\{type}(\#)<\\{math\_node})$\par
\P\D \37$\\{non\_discardable}(\#)\S(\\{type}(\#)<\\{math\_node})$\par
\fi

\M149. A \\{glue\_node} represents glue in a list. However, it is really only
a pointer to a separate glue specification, since \TeX\ makes use of the
fact that many essentially identical nodes of glue are usually present.
If \|p points to a \\{glue\_node}, $\\{glue\_ptr}(\|p)$ points to
another packet of words that specify the stretch and shrink components, etc.

Glue nodes also serve to represent leaders; the \\{subtype} is used to
distinguish between ordinary glue (which is called \\{normal}) and the three
kinds of leaders (which are called \\{a\_leaders}, \\{c\_leaders}, and \\{x%
\_leaders}).
The \\{leader\_ptr} field points to a rule node or to a box node containing the
leaders; it is set to \\{null} in ordinary glue nodes.

Many kinds of glue are computed from \TeX's ``skip'' parameters, and
it is helpful to know which parameter has led to a particular glue node.
Therefore the \\{subtype} is set to indicate the source of glue, whenever
it originated as a parameter. We will be defining symbolic names for the
parameter numbers later (e.g., $\\{line\_skip\_code}=0$, $\\{baseline\_skip%
\_code}=1$,
etc.); it suffices for now to say that the \\{subtype} of parametric glue
will be the same as the parameter number, plus one.

In math formulas there are two more possibilities for the \\{subtype} in a
glue node: \\{mu\_glue} denotes an \.{\\mskip} (where the units are scaled %
\.{mu}
instead of scaled \.{pt}); and \\{cond\_math\_glue} denotes the `\.{%
\\nonscript}'
feature that cancels the glue node immediately following if it appears
in a subscript.

\Y\P\D \37$\\{glue\_node}=10$\C{\\{type} of node that points to a glue
specification}\par
\P\D \37$\\{cond\_math\_glue}=98$\C{special \\{subtype} to suppress glue in the
next node}\par
\P\D \37$\\{mu\_glue}=99$\C{\\{subtype} for math glue}\par
\P\D \37$\\{a\_leaders}=100$\C{\\{subtype} for aligned leaders}\par
\P\D \37$\\{c\_leaders}=101$\C{\\{subtype} for centered leaders}\par
\P\D \37$\\{x\_leaders}=102$\C{\\{subtype} for expanded leaders}\par
\P\D \37$\\{glue\_ptr}\S\\{llink}$\C{pointer to a glue specification}\par
\P\D \37$\\{leader\_ptr}\S\\{rlink}$\C{pointer to box or rule node for leaders}%
\par
\fi

\M150. A glue specification has a halfword reference count in its first word,
representing \\{null} plus the number of glue nodes that point to it (less
one).
Note that the reference count appears in the same position as
the \\{link} field in list nodes; this is the field that is initialized
to \\{null} when a node is allocated, and it is also the field that is flagged
by \\{empty\_flag} in empty nodes.

Glue specifications also contain three \\{scaled} fields, for the \\{width},
\\{stretch}, and \\{shrink} dimensions. Finally, there are two one-byte
fields called \\{stretch\_order} and \\{shrink\_order}; these contain the
orders of infinity (\\{normal}, \\{fil}, \\{fill}, or \\{filll})
corresponding to the stretch and shrink values.

\Y\P\D \37$\\{glue\_spec\_size}=4$\C{number of words to allocate for a glue
specification}\par
\P\D \37$\\{glue\_ref\_count}(\#)\S\\{link}(\#)$\C{reference count of a glue
specification}\par
\P\D \37$\\{stretch}(\#)\S\\{mem}[\#+2].\\{sc}$\C{the stretchability of this
glob of glue}\par
\P\D \37$\\{shrink}(\#)\S\\{mem}[\#+3].\\{sc}$\C{the shrinkability of this glob
of glue}\par
\P\D \37$\\{stretch\_order}\S\\{type}$\C{order of infinity for stretching}\par
\P\D \37$\\{shrink\_order}\S\\{subtype}$\C{order of infinity for shrinking}\par
\P\D \37$\\{fil}=1$\C{first-order infinity}\par
\P\D \37$\\{fill}=2$\C{second-order infinity}\par
\P\D \37$\\{filll}=3$\C{third-order infinity}\par
\Y\P$\4\X18:Types in the outer block\X\mathrel{+}\S$\6
$\\{glue\_ord}=\\{normal}\to\\{filll}$;\C{infinity to the 0, 1, 2, or 3 power}%
\par
\fi

\M151. Here is a function that returns a pointer to a copy of a glue spec.
The reference count in the copy is \\{null}, because there is assumed
to be exactly one reference to the new specification.

\Y\P\4\&{function}\1\  \37$\\{new\_spec}(\|p:\\{pointer})$: \37\\{pointer};%
\C{duplicates a glue specification}\6
\4\&{var} \37\|q: \37\\{pointer};\C{the new spec}\2\6
\&{begin} \37$\|q\K\\{get\_node}(\\{glue\_spec\_size})$;\6
$\\{mem}[\|q]\K\\{mem}[\|p]$;\5
$\\{glue\_ref\_count}(\|q)\K\\{null}$;\6
$\\{width}(\|q)\K\\{width}(\|p)$;\5
$\\{stretch}(\|q)\K\\{stretch}(\|p)$;\5
$\\{shrink}(\|q)\K\\{shrink}(\|p)$;\5
$\\{new\_spec}\K\|q$;\6
\&{end};\par
\fi

\M152. And here's a function that creates a glue node for a given parameter
identified by its code number; for example,
$\\{new\_param\_glue}(\\{line\_skip\_code})$ returns a pointer to a glue node
for the
current \.{\\lineskip}.

\Y\P\4\&{function}\1\  \37$\\{new\_param\_glue}(\|n:\\{small\_number})$: \37%
\\{pointer};\6
\4\&{var} \37\|p: \37\\{pointer};\C{the new node}\6
\|q: \37\\{pointer};\C{the glue specification}\2\6
\&{begin} \37$\|p\K\\{get\_node}(\\{small\_node\_size})$;\5
$\\{type}(\|p)\K\\{glue\_node}$;\5
$\\{subtype}(\|p)\K\|n+1$;\5
$\\{leader\_ptr}(\|p)\K\\{null}$;\6
$\|q\K\X224:Current \\{mem} equivalent of glue parameter number \|n\X\hbox{}$;\5
$\\{glue\_ptr}(\|p)\K\|q$;\5
$\\{incr}(\\{glue\_ref\_count}(\|q))$;\5
$\\{new\_param\_glue}\K\|p$;\6
\&{end};\par
\fi

\M153. Glue nodes that are more or less anonymous are created by \\{new\_glue},
whose argument points to a glue specification.

\Y\P\4\&{function}\1\  \37$\\{new\_glue}(\|q:\\{pointer})$: \37\\{pointer};\6
\4\&{var} \37\|p: \37\\{pointer};\C{the new node}\2\6
\&{begin} \37$\|p\K\\{get\_node}(\\{small\_node\_size})$;\5
$\\{type}(\|p)\K\\{glue\_node}$;\5
$\\{subtype}(\|p)\K\\{normal}$;\5
$\\{leader\_ptr}(\|p)\K\\{null}$;\5
$\\{glue\_ptr}(\|p)\K\|q$;\5
$\\{incr}(\\{glue\_ref\_count}(\|q))$;\5
$\\{new\_glue}\K\|p$;\6
\&{end};\par
\fi

\M154. Still another subroutine is needed: this one is sort of a combination
of \\{new\_param\_glue} and \\{new\_glue}. It creates a glue node for one of
the current glue parameters, but it makes a fresh copy of the glue
specification, since that specification will probably be subject to change,
while the parameter will stay put. The global variable \\{temp\_ptr} is
set to the address of the new spec.

\Y\P\4\&{function}\1\  \37$\\{new\_skip\_param}(\|n:\\{small\_number})$: \37%
\\{pointer};\6
\4\&{var} \37\|p: \37\\{pointer};\C{the new node}\2\6
\&{begin} \37$\\{temp\_ptr}\K\\{new\_spec}(\X224:Current \\{mem} equivalent of
glue parameter number \|n\X)$;\5
$\|p\K\\{new\_glue}(\\{temp\_ptr})$;\5
$\\{glue\_ref\_count}(\\{temp\_ptr})\K\\{null}$;\5
$\\{subtype}(\|p)\K\|n+1$;\5
$\\{new\_skip\_param}\K\|p$;\6
\&{end};\par
\fi

\M155. A \\{kern\_node} has a \\{width} field to specify a (normally negative)
amount of spacing. This spacing correction appears in horizontal lists
between letters like A and V when the font designer said that it looks
better to move them closer together or further apart. A kern node can
also appear in a vertical list, when its `\\{width}' denotes additional
spacing in the vertical direction. The \\{subtype} is either \\{normal} (for
kerns inserted from font information or math mode calculations) or \\{explicit}
(for kerns inserted from \.{\\kern} and \.{\\/} commands) or \\{acc\_kern}
(for kerns inserted from non-math accents) or \\{mu\_glue} (for kerns
inserted from \.{\\mkern} specifications in math formulas).

\Y\P\D \37$\\{kern\_node}=11$\C{\\{type} of a kern node}\par
\P\D \37$\\{explicit}=1$\C{\\{subtype} of kern nodes from \.{\\kern} and \.{%
\\/}}\par
\P\D \37$\\{acc\_kern}=2$\C{\\{subtype} of kern nodes from accents}\par
\fi

\M156. The \\{new\_kern} function creates a kern node having a given width.

\Y\P\4\&{function}\1\  \37$\\{new\_kern}(\|w:\\{scaled})$: \37\\{pointer};\6
\4\&{var} \37\|p: \37\\{pointer};\C{the new node}\2\6
\&{begin} \37$\|p\K\\{get\_node}(\\{small\_node\_size})$;\5
$\\{type}(\|p)\K\\{kern\_node}$;\5
$\\{subtype}(\|p)\K\\{normal}$;\5
$\\{width}(\|p)\K\|w$;\5
$\\{new\_kern}\K\|p$;\6
\&{end};\par
\fi

\M157. A \\{penalty\_node} specifies the penalty associated with line or page
breaking, in its \\{penalty} field. This field is a fullword integer, but
the full range of integer values is not used: Any penalty $\G10000$ is
treated as infinity, and no break will be allowed for such high values.
Similarly, any penalty $\L-10000$ is treated as negative infinity, and a
break will be forced.

\Y\P\D \37$\\{penalty\_node}=12$\C{\\{type} of a penalty node}\par
\P\D \37$\\{inf\_penalty}=\\{inf\_bad}$\C{``infinite'' penalty value}\par
\P\D \37$\\{eject\_penalty}=-\\{inf\_penalty}$\C{``negatively infinite''
penalty value}\par
\P\D \37$\\{penalty}(\#)\S\\{mem}[\#+1].\\{int}$\C{the added cost of breaking a
list here}\par
\fi

\M158. Anyone who has been reading the last few sections of the program will
be able to guess what comes next.

\Y\P\4\&{function}\1\  \37$\\{new\_penalty}(\|m:\\{integer})$: \37\\{pointer};\6
\4\&{var} \37\|p: \37\\{pointer};\C{the new node}\2\6
\&{begin} \37$\|p\K\\{get\_node}(\\{small\_node\_size})$;\5
$\\{type}(\|p)\K\\{penalty\_node}$;\5
$\\{subtype}(\|p)\K0$;\C{the \\{subtype} is not used}\6
$\\{penalty}(\|p)\K\|m$;\5
$\\{new\_penalty}\K\|p$;\6
\&{end};\par
\fi

\M159. You might think that we have introduced enough node types by now. Well,
almost, but there is one more: An \\{unset\_node} has nearly the same format
as an \\{hlist\_node} or \\{vlist\_node}; it is used for entries in \.{%
\\halign}
or \.{\\valign} that are not yet in their final form, since the box
dimensions are their ``natural'' sizes before any glue adjustment has been
made. The \\{glue\_set} word is not present; instead, we have a \\{glue%
\_stretch}
field, which contains the total stretch of order \\{glue\_order} that is
present in the hlist or vlist being boxed.
Similarly, the \\{shift\_amount} field is replaced by a \\{glue\_shrink} field,
containing the total shrink of order \\{glue\_sign} that is present.
The \\{subtype} field is called \\{span\_count}; an unset box typically
contains the data for $\\{qo}(\\{span\_count})+1$ columns.
Unset nodes will be changed to box nodes when alignment is completed.

\Y\P\D \37$\\{unset\_node}=13$\C{\\{type} for an unset node}\par
\P\D \37$\\{glue\_stretch}(\#)\S\\{mem}[\#+\\{glue\_offset}].\\{sc}$\C{total
stretch in an unset node}\par
\P\D \37$\\{glue\_shrink}\S\\{shift\_amount}$\C{total shrink in an unset node}%
\par
\P\D \37$\\{span\_count}\S\\{subtype}$\C{indicates the number of spanned
columns}\par
\fi

\M160. In fact, there are still more types coming. When we get to math formula
processing we will see that a \\{style\_node} has $\\{type}=14$; and a number
of larger type codes will also be defined, for use in math mode only.

\fi

\M161. Warning: If any changes are made to these data structure layouts, such
as
changing any of the node sizes or even reordering the words of nodes,
the \\{copy\_node\_list} procedure and the memory initialization code
below may have to be changed. Such potentially dangerous parts of the
program are listed in the index under `data structure assumptions'.
However, other references to the nodes are made symbolically in terms of
the \.{WEB} macro definitions above, so that format changes will leave
\TeX's other algorithms intact.
\fi

\N162.  \[11] Memory layout.
Some areas of \\{mem} are dedicated to fixed usage, since static allocation is
more efficient than dynamic allocation when we can get away with it. For
example, locations \\{mem\_bot} to $\\{mem\_bot}+3$ are always used to store
the
specification for glue that is `\.{0pt plus 0pt minus 0pt}'. The
following macro definitions accomplish the static allocation by giving
symbolic names to the fixed positions. Static variable-size nodes appear
in locations \\{mem\_bot} through \\{lo\_mem\_stat\_max}, and static
single-word nodes
appear in locations \\{hi\_mem\_stat\_min} through \\{mem\_top}, inclusive. It
is
harmless to let \\{lig\_trick} and \\{garbage} share the same location of %
\\{mem}.

\Y\P\D \37$\\{zero\_glue}\S\\{mem\_bot}$\C{specification for \.{0pt plus 0pt
minus 0pt}}\par
\P\D \37$\\{fil\_glue}\S\\{zero\_glue}+\\{glue\_spec\_size}$\C{\.{0pt plus 1fil
minus 0pt}}\par
\P\D \37$\\{fill\_glue}\S\\{fil\_glue}+\\{glue\_spec\_size}$\C{\.{0pt plus
1fill minus 0pt}}\par
\P\D \37$\\{ss\_glue}\S\\{fill\_glue}+\\{glue\_spec\_size}$\C{\.{0pt plus 1fil
minus 1fil}}\par
\P\D \37$\\{fil\_neg\_glue}\S\\{ss\_glue}+\\{glue\_spec\_size}$\C{\.{0pt plus
-1fil minus 0pt}}\par
\P\D \37$\\{lo\_mem\_stat\_max}\S\\{fil\_neg\_glue}+\\{glue\_spec\_size}-1$%
\C{largest statically 	allocated word in the variable-size \\{mem}}\Y\par
\P\D \37$\\{page\_ins\_head}\S\\{mem\_top}$\C{list of insertion data for
current page}\par
\P\D \37$\\{contrib\_head}\S\\{mem\_top}-1$\C{vlist of items not yet on current
page}\par
\P\D \37$\\{page\_head}\S\\{mem\_top}-2$\C{vlist for current page}\par
\P\D \37$\\{temp\_head}\S\\{mem\_top}-3$\C{head of a temporary list of some
kind}\par
\P\D \37$\\{hold\_head}\S\\{mem\_top}-4$\C{head of a temporary list of another
kind}\par
\P\D \37$\\{adjust\_head}\S\\{mem\_top}-5$\C{head of adjustment list returned
by \\{hpack}}\par
\P\D \37$\\{active}\S\\{mem\_top}-7$\C{head of active list in \\{line\_break},
needs two words}\par
\P\D \37$\\{align\_head}\S\\{mem\_top}-8$\C{head of preamble list for
alignments}\par
\P\D \37$\\{end\_span}\S\\{mem\_top}-9$\C{tail of spanned-width lists}\par
\P\D \37$\\{omit\_template}\S\\{mem\_top}-10$\C{a constant token list}\par
\P\D \37$\\{null\_list}\S\\{mem\_top}-11$\C{permanently empty list}\par
\P\D \37$\\{lig\_trick}\S\\{mem\_top}-12$\C{a ligature masquerading as a %
\\{char\_node}}\par
\P\D \37$\\{garbage}\S\\{mem\_top}-12$\C{used for scrap information}\par
\P\D \37$\\{backup\_head}\S\\{mem\_top}-13$\C{head of token list built by %
\\{scan\_keyword}}\par
\P\D \37$\\{hi\_mem\_stat\_min}\S\\{mem\_top}-13$\C{smallest statically
allocated word in 	the one-word \\{mem}}\par
\P\D \37$\\{hi\_mem\_stat\_usage}=14$\C{the number of one-word nodes always
present}\par
\fi

\M163. The following code gets \\{mem} off to a good start, when \TeX\ is
initializing itself the slow way.

\Y\P$\4\X19:Local variables for initialization\X\mathrel{+}\S$\6
\4\|k: \37\\{integer};\C{index into \\{mem}, \\{eqtb}, etc.}\par
\fi

\M164. \P$\X164:Initialize table entries (done by \.{INITEX} only)\X\S$\6
\&{for} $\|k\K\\{mem\_bot}+1\mathrel{\&{to}}\\{lo\_mem\_stat\_max}$ \1\&{do}\5
$\\{mem}[\|k].\\{sc}\K0$;\C{all glue dimensions are zeroed}\2\6
$\|k\K\\{mem\_bot}$;\ \&{while} $\|k\L\\{lo\_mem\_stat\_max}$ \1\&{do}\C{set
first words of glue specifications}\6
\&{begin} \37$\\{glue\_ref\_count}(\|k)\K\\{null}+1$;\5
$\\{stretch\_order}(\|k)\K\\{normal}$;\5
$\\{shrink\_order}(\|k)\K\\{normal}$;\5
$\|k\K\|k+\\{glue\_spec\_size}$;\6
\&{end};\2\6
$\\{stretch}(\\{fil\_glue})\K\\{unity}$;\5
$\\{stretch\_order}(\\{fil\_glue})\K\\{fil}$;\6
$\\{stretch}(\\{fill\_glue})\K\\{unity}$;\5
$\\{stretch\_order}(\\{fill\_glue})\K\\{fill}$;\6
$\\{stretch}(\\{ss\_glue})\K\\{unity}$;\5
$\\{stretch\_order}(\\{ss\_glue})\K\\{fil}$;\6
$\\{shrink}(\\{ss\_glue})\K\\{unity}$;\5
$\\{shrink\_order}(\\{ss\_glue})\K\\{fil}$;\6
$\\{stretch}(\\{fil\_neg\_glue})\K-\\{unity}$;\5
$\\{stretch\_order}(\\{fil\_neg\_glue})\K\\{fil}$;\6
$\\{rover}\K\\{lo\_mem\_stat\_max}+1$;\5
$\\{link}(\\{rover})\K\\{empty\_flag}$;\C{now initialize the dynamic memory}\6
$\\{node\_size}(\\{rover})\K1000$;\C{which is a 1000-word available node}\6
$\\{llink}(\\{rover})\K\\{rover}$;\5
$\\{rlink}(\\{rover})\K\\{rover}$;\6
$\\{lo\_mem\_max}\K\\{rover}+1000$;\5
$\\{link}(\\{lo\_mem\_max})\K\\{null}$;\5
$\\{info}(\\{lo\_mem\_max})\K\\{null}$;\6
\&{for} $\|k\K\\{hi\_mem\_stat\_min}\mathrel{\&{to}}\\{mem\_top}$ \1\&{do}\5
$\\{mem}[\|k]\K\\{mem}[\\{lo\_mem\_max}]$;\C{clear list heads}\2\6
\X790:Initialize the special list heads and constant nodes\X;\6
$\\{avail}\K\\{null}$;\5
$\\{mem\_end}\K\\{mem\_top}$;\5
$\\{hi\_mem\_min}\K\\{hi\_mem\_stat\_min}$;\C{initialize the one-word memory}\6
$\\{var\_used}\K\\{lo\_mem\_stat\_max}+1-\\{mem\_bot}$;\5
$\\{dyn\_used}\K\\{hi\_mem\_stat\_usage}$;\C{initialize statistics}\par
\A sections~222, 228, 232\*, 240, 250, 258, 552, 952, 1216, 1301, and~1369.
\U section~8\*.\fi

\M165. If \TeX\ is extended improperly, the \\{mem} array might get screwed up.
For example, some pointers might be wrong, or some ``dead'' nodes might not
have been freed when the last reference to them disappeared. Procedures
\\{check\_mem} and \\{search\_mem} are available to help diagnose such
problems. These procedures make use of two arrays called \\{free} and
\\{was\_free} that are present only if \TeX's debugging routines have
been included. (You may want to decrease the size of \\{mem} while you
are debugging.)

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\&{debug} \37\\{free}: \37\&{packed} \37\&{array} $[\\{mem\_min}\to\\{mem%
\_max}]$ \1\&{of}\5
\\{boolean};\C{free cells}\2\6
\4\hbox{\hskip1em}\\{was\_free}: \37\&{packed} \37\&{array} $[\\{mem\_min}\to%
\\{mem\_max}]$ \1\&{of}\5
\\{boolean};\C{previously free cells}\2\6
\4$\hbox{\hskip1em}\\{was\_mem\_end},\39\\{was\_lo\_max},\39\\{was\_hi\_min}$: %
\37\\{pointer};\C{previous \\{mem\_end}, \\{lo\_mem\_max}, and \\{hi\_mem%
\_min}}\6
\4\hbox{\hskip1em}\\{panicking}: \37\\{boolean};\C{do we want to check memory
constantly?}\6
\&{gubed}\par
\fi

\M166. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
\&{debug} \37$\\{was\_mem\_end}\K\\{mem\_min}$;\C{indicate that everything was
previously free}\6
$\\{was\_lo\_max}\K\\{mem\_min}$;\5
$\\{was\_hi\_min}\K\\{mem\_max}$;\5
$\\{panicking}\K\\{false}$;\6
\&{gubed}\par
\fi

\M167. Procedure \\{check\_mem} makes sure that the available space lists of
\\{mem} are well formed, and it optionally prints out all locations
that are reserved now but were free the last time this procedure was called.

\Y\P\&{debug} \37\&{procedure}\1\  \37$\\{check\_mem}(\\{print\_locs}:%
\\{boolean})$;\6
\4\&{label} \37$\\{done1},\39\\{done2}$;\C{loop exits}\6
\4\&{var} \37$\|p,\39\|q$: \37\\{pointer};\C{current locations of interest in %
\\{mem}}\6
\\{clobbered}: \37\\{boolean};\C{is something amiss?}\2\6
\&{begin} \37\&{for} $\|p\K\\{mem\_min}\mathrel{\&{to}}\\{lo\_mem\_max}$ \1%
\&{do}\5
$\\{free}[\|p]\K\\{false}$;\C{you can probably 	do this faster}\2\6
\&{for} $\|p\K\\{hi\_mem\_min}\mathrel{\&{to}}\\{mem\_end}$ \1\&{do}\5
$\\{free}[\|p]\K\\{false}$;\C{ditto}\2\6
\X168:Check single-word \\{avail} list\X;\6
\X169:Check variable-size \\{avail} list\X;\6
\X170:Check flags of unavailable nodes\X;\6
\&{if} $\\{print\_locs}$ \1\&{then}\5
\X171:Print newly busy locations\X;\2\6
\&{for} $\|p\K\\{mem\_min}\mathrel{\&{to}}\\{lo\_mem\_max}$ \1\&{do}\5
$\\{was\_free}[\|p]\K\\{free}[\|p]$;\2\6
\&{for} $\|p\K\\{hi\_mem\_min}\mathrel{\&{to}}\\{mem\_end}$ \1\&{do}\5
$\\{was\_free}[\|p]\K\\{free}[\|p]$;\C{$\\{was\_free}\K\\{free}$ might be
faster}\2\6
$\\{was\_mem\_end}\K\\{mem\_end}$;\5
$\\{was\_lo\_max}\K\\{lo\_mem\_max}$;\5
$\\{was\_hi\_min}\K\\{hi\_mem\_min}$;\6
\&{end};\6
\&{gubed}\par
\fi

\M168. \P$\X168:Check single-word \\{avail} list\X\S$\6
$\|p\K\\{avail}$;\5
$\|q\K\\{null}$;\5
$\\{clobbered}\K\\{false}$;\6
\&{while} $\|p\I\\{null}$ \1\&{do}\6
\&{begin} \37\&{if} $(\|p>\\{mem\_end})\V(\|p<\\{hi\_mem\_min})$ \1\&{then}\5
$\\{clobbered}\K\\{true}$\6
\4\&{else} \&{if} $\\{free}[\|p]$ \1\&{then}\5
$\\{clobbered}\K\\{true}$;\2\2\6
\&{if} $\\{clobbered}$ \1\&{then}\6
\&{begin} \37$\\{print\_nl}(\.{"AVAIL\ list\ clobbered\ at\ "})$;\5
$\\{print\_int}(\|q)$;\5
\&{goto} \37\\{done1};\6
\&{end};\2\6
$\\{free}[\|p]\K\\{true}$;\5
$\|q\K\|p$;\5
$\|p\K\\{link}(\|q)$;\6
\&{end};\2\6
\4\\{done1}: \37\par
\U section~167.\fi

\M169. \P$\X169:Check variable-size \\{avail} list\X\S$\6
$\|p\K\\{rover}$;\5
$\|q\K\\{null}$;\5
$\\{clobbered}\K\\{false}$;\6
\1\&{repeat} \37\&{if} $(\|p\G\\{lo\_mem\_max})\V(\|p<\\{mem\_min})$ \1\&{then}%
\5
$\\{clobbered}\K\\{true}$\6
\4\&{else} \&{if} $(\\{rlink}(\|p)\G\\{lo\_mem\_max})\V(\\{rlink}(\|p)<\\{mem%
\_min})$ \1\&{then}\5
$\\{clobbered}\K\\{true}$\6
\4\&{else} \&{if} $\R(\\{is\_empty}(\|p))\V(\\{node\_size}(\|p)<2)\V\30(\|p+%
\\{node\_size}(\|p)>\\{lo\_mem\_max})\V\30(\\{llink}(\\{rlink}(\|p))\I\|p)$ \1%
\&{then}\5
$\\{clobbered}\K\\{true}$;\2\2\2\6
\&{if} $\\{clobbered}$ \1\&{then}\6
\&{begin} \37$\\{print\_nl}(\.{"Double-AVAIL\ list\ clobbered\ at\ "})$;\5
$\\{print\_int}(\|q)$;\5
\&{goto} \37\\{done2};\6
\&{end};\2\6
\&{for} $\|q\K\|p\mathrel{\&{to}}\|p+\\{node\_size}(\|p)-1$ \1\&{do}\C{mark all
locations free}\6
\&{begin} \37\&{if} $\\{free}[\|q]$ \1\&{then}\6
\&{begin} \37$\\{print\_nl}(\.{"Doubly\ free\ location\ at\ "})$;\5
$\\{print\_int}(\|q)$;\5
\&{goto} \37\\{done2};\6
\&{end};\2\6
$\\{free}[\|q]\K\\{true}$;\6
\&{end};\2\6
$\|q\K\|p$;\5
$\|p\K\\{rlink}(\|p)$;\6
\4\&{until}\5
$\|p=\\{rover}$;\2\6
\4\\{done2}: \37\par
\U section~167.\fi

\M170. \P$\X170:Check flags of unavailable nodes\X\S$\6
$\|p\K\\{mem\_min}$;\6
\&{while} $\|p\L\\{lo\_mem\_max}$ \1\&{do}\C{node \|p should not be empty}\6
\&{begin} \37\&{if} $\\{is\_empty}(\|p)$ \1\&{then}\6
\&{begin} \37$\\{print\_nl}(\.{"Bad\ flag\ at\ "})$;\5
$\\{print\_int}(\|p)$;\6
\&{end};\2\6
\&{while} $(\|p\L\\{lo\_mem\_max})\W\R\\{free}[\|p]$ \1\&{do}\5
$\\{incr}(\|p)$;\2\6
\&{while} $(\|p\L\\{lo\_mem\_max})\W\\{free}[\|p]$ \1\&{do}\5
$\\{incr}(\|p)$;\2\6
\&{end}\2\par
\U section~167.\fi

\M171. \P$\X171:Print newly busy locations\X\S$\6
\&{begin} \37$\\{print\_nl}(\.{"New\ busy\ locs:"})$;\6
\&{for} $\|p\K\\{mem\_min}\mathrel{\&{to}}\\{lo\_mem\_max}$ \1\&{do}\6
\&{if} $\R\\{free}[\|p]\W((\|p>\\{was\_lo\_max})\V\\{was\_free}[\|p])$ \1%
\&{then}\6
\&{begin} \37$\\{print\_char}(\.{"\ "})$;\5
$\\{print\_int}(\|p)$;\6
\&{end};\2\2\6
\&{for} $\|p\K\\{hi\_mem\_min}\mathrel{\&{to}}\\{mem\_end}$ \1\&{do}\6
\&{if} $\R\\{free}[\|p]\W((\|p<\\{was\_hi\_min})\V(\|p>\\{was\_mem\_end})\V%
\\{was\_free}[\|p])$ \1\&{then}\6
\&{begin} \37$\\{print\_char}(\.{"\ "})$;\5
$\\{print\_int}(\|p)$;\6
\&{end};\2\2\6
\&{end}\par
\U section~167.\fi

\M172. The \\{search\_mem} procedure attempts to answer the question ``Who
points
to node~\|p?'' In doing so, it fetches \\{link} and \\{info} fields of \\{mem}
that might not be of type \\{two\_halves}. Strictly speaking, this is
undefined in \PASCAL, and it can lead to ``false drops'' (words that seem to
point to \|p purely by coincidence). But for debugging purposes, we want
to rule out the places that do {\sl not\/} point to \|p, so a few false
drops are tolerable.

\Y\P\&{debug} \37\&{procedure}\1\  \37$\\{search\_mem}(\|p:\\{pointer})$;%
\C{look for pointers to \|p}\6
\4\&{var} \37\|q: \37\\{integer};\C{current position being searched}\2\6
\&{begin} \37\&{for} $\|q\K\\{mem\_min}\mathrel{\&{to}}\\{lo\_mem\_max}$ \1%
\&{do}\6
\&{begin} \37\&{if} $\\{link}(\|q)=\|p$ \1\&{then}\6
\&{begin} \37$\\{print\_nl}(\.{"LINK("})$;\5
$\\{print\_int}(\|q)$;\5
$\\{print\_char}(\.{")"})$;\6
\&{end};\2\6
\&{if} $\\{info}(\|q)=\|p$ \1\&{then}\6
\&{begin} \37$\\{print\_nl}(\.{"INFO("})$;\5
$\\{print\_int}(\|q)$;\5
$\\{print\_char}(\.{")"})$;\6
\&{end};\2\6
\&{end};\2\6
\&{for} $\|q\K\\{hi\_mem\_min}\mathrel{\&{to}}\\{mem\_end}$ \1\&{do}\6
\&{begin} \37\&{if} $\\{link}(\|q)=\|p$ \1\&{then}\6
\&{begin} \37$\\{print\_nl}(\.{"LINK("})$;\5
$\\{print\_int}(\|q)$;\5
$\\{print\_char}(\.{")"})$;\6
\&{end};\2\6
\&{if} $\\{info}(\|q)=\|p$ \1\&{then}\6
\&{begin} \37$\\{print\_nl}(\.{"INFO("})$;\5
$\\{print\_int}(\|q)$;\5
$\\{print\_char}(\.{")"})$;\6
\&{end};\2\6
\&{end};\2\6
\X255:Search \\{eqtb} for equivalents equal to \|p\X;\6
\X285:Search \\{save\_stack} for equivalents that point to \|p\X;\6
\X933:Search \\{hyph\_list} for pointers to \|p\X;\6
\&{end};\6
\&{gubed}\par
\fi

\N173.  \[12] Displaying boxes.
We can reinforce our knowledge of the data structures just introduced
by considering two procedures that display a list in symbolic form.
The first of these, called \\{short\_display}, is used in ``overfull box''
messages to give the top-level description of a list. The other one,
called \\{show\_node\_list}, prints a detailed description of exactly what
is in the data structure.

The philosophy of \\{short\_display} is to ignore the fine points about exactly
what is inside boxes, except that ligatures and discretionary breaks are
expanded. As a result, \\{short\_display} is a recursive procedure, but the
recursion is never more than one level deep.

A global variable \\{font\_in\_short\_display} keeps track of the font code
that
is assumed to be present when \\{short\_display} begins; deviations from this
font will be printed.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{font\_in\_short\_display}: \37\\{integer};\C{an internal font number}\par
\fi

\M174\*. Boxes, rules, inserts, whatsits, marks, and things in general that are
sort of ``complicated'' are indicated only by printing `\.{[]}'.

\Y\P\4\&{procedure}\1\  \37$\\{short\_display}(\|p:\\{integer})$;\C{prints
highlights of list \|p}\6
\4\&{label} \37\\{done};\6
\4\&{var} \37\|n: \37\\{integer};\C{for replacement counts}\6
\\{ext}: \37\\{integer};\C{amount added to character code by xchar}\2\6
\&{begin} \37$\\{ext}\K0$;\6
\&{while} $\|p>\\{mem\_min}$ \1\&{do}\6
\&{begin} \37\&{if} $\\{is\_char\_node}(\|p)$ \1\&{then}\6
\&{begin} \37\&{if} $\|p\L\\{mem\_end}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{is\_xchar\_node}(\|p)$ \1\&{then}\6
\&{begin} \37$\\{ext}\K256\ast(\\{qo}(\\{character}(\|p)))$;\5
\&{goto} \37\\{done};\6
\&{end};\2\6
\&{if} $\\{font}(\|p)\I\\{font\_in\_short\_display}$ \1\&{then}\6
\&{begin} \37\&{if} $(\\{font}(\|p)<\\{font\_base})\V(\\{font}(\|p)>\\{font%
\_max})$ \1\&{then}\5
$\\{print\_char}(\.{"*"})$\6
\4\&{else} \X267:Print the font identifier for $\\{font}(\|p)$\X;\2\6
$\\{print\_char}(\.{"\ "})$;\5
$\\{font\_in\_short\_display}\K\\{font}(\|p)$;\6
\&{end};\2\6
$\\{print\_ASCII}(\\{ext}+\\{qo}(\\{character}(\|p)))$;\5
$\\{ext}\K0$;\6
\&{end};\2\6
\&{end}\6
\4\&{else} \X175:Print a short indication of the contents of node \|p\X;\2\6
\4\\{done}: \37$\|p\K\\{link}(\|p)$;\6
\&{end};\2\6
\&{end};\par
\fi

\M175. \P$\X175:Print a short indication of the contents of node \|p\X\S$\6
\&{case} $\\{type}(\|p)$ \1\&{of}\6
\4$\\{hlist\_node},\39\\{vlist\_node},\39\\{ins\_node},\39\\{whatsit\_node},\39%
\\{mark\_node},\39\\{adjust\_node},\39\\{unset\_node}$: \37$\\{print}(%
\.{"[]"})$;\6
\4\\{rule\_node}: \37$\\{print\_char}(\.{"|"})$;\6
\4\\{glue\_node}: \37\&{if} $\\{glue\_ptr}(\|p)\I\\{zero\_glue}$ \1\&{then}\5
$\\{print\_char}(\.{"\ "})$;\2\6
\4\\{math\_node}: \37$\\{print\_char}(\.{"\$"})$;\6
\4\\{ligature\_node}: \37$\\{short\_display}(\\{lig\_ptr}(\|p))$;\6
\4\\{disc\_node}: \37\&{begin} \37$\\{short\_display}(\\{pre\_break}(\|p))$;\5
$\\{short\_display}(\\{post\_break}(\|p))$;\6
$\|n\K\\{replace\_count}(\|p)$;\6
\&{while} $\|n>0$ \1\&{do}\6
\&{begin} \37\&{if} $\\{link}(\|p)\I\\{null}$ \1\&{then}\5
$\|p\K\\{link}(\|p)$;\2\6
$\\{decr}(\|n)$;\6
\&{end};\2\6
\&{end};\6
\4\&{othercases} \37\\{do\_nothing}\2\6
\&{endcases}\par
\U section~174\*.\fi

\M176\*. The \\{show\_node\_list} routine requires some auxiliary subroutines:
one to
print a font-and-character combination, one to print a token list without
its reference count, and one to print a rule dimension.

\Y\P\4\&{procedure}\1\  \37$\\{print\_font\_and\_char}(\|p:\\{integer})$;%
\C{prints \\{char\_node} data}\6
\4\&{label} \37\\{reswitch};\6
\4\&{var} \37\\{ext}: \37\\{integer};\C{amount added to character code by
xchar, or $-1$}\2\6
\&{begin} \37$\\{ext}\K-1$;\6
\4\\{reswitch}: \37\&{if} $\|p>\\{mem\_end}$ \1\&{then}\5
$\\{print\_esc}(\.{"CLOBBERED."})$\6
\4\&{else} \&{begin} \37\&{if} $\\{is\_xchar\_node}(\|p)$ \1\&{then}\6
\&{begin} \37$\\{ext}\K\\{qo}(\\{character}(\|p))$;\5
$\|p\K\\{link}(\|p)$;\5
\&{goto} \37\\{reswitch};\6
\&{end};\2\6
\&{if} $(\\{font}(\|p)<\\{font\_base})\V(\\{font}(\|p)>\\{font\_max})$ \1%
\&{then}\5
$\\{print\_char}(\.{"*"})$\6
\4\&{else} \X267:Print the font identifier for $\\{font}(\|p)$\X;\2\6
$\\{print\_char}(\.{"\ "})$;\6
\&{if} $\\{ext}<0$ \1\&{then}\5
$\\{print\_ASCII}(\\{qo}(\\{character}(\|p)))$\6
\4\&{else} \&{begin} \37$\\{print\_esc}(\.{"xchar"})$;\5
$\\{print\_hex}(\\{ext}\ast256+\\{qo}(\\{character}(\|p)))$;\6
\&{end};\2\6
\&{end};\2\6
\&{end};\7
\4\&{procedure}\1\  \37$\\{print\_mark}(\|p:\\{integer})$;\C{prints token list
data in braces}\2\6
\&{begin} \37$\\{print\_char}(\.{"\{"})$;\6
\&{if} $(\|p<\\{hi\_mem\_min})\V(\|p>\\{mem\_end})$ \1\&{then}\5
$\\{print\_esc}(\.{"CLOBBERED."})$\6
\4\&{else} $\\{show\_token\_list}(\\{link}(\|p),\39\\{null},\39\\{max\_print%
\_line}-10)$;\2\6
$\\{print\_char}(\.{"\}"})$;\6
\&{end};\7
\4\&{procedure}\1\  \37$\\{print\_rule\_dimen}(\|d:\\{scaled})$;\C{prints
dimension in rule node}\2\6
\&{begin} \37\&{if} $\\{is\_running}(\|d)$ \1\&{then}\5
$\\{print\_char}(\.{"*"})$\6
\4\&{else} $\\{print\_scaled}(\|d)$;\2\6
\&{end};\par
\fi

\M177. Then there is a subroutine that prints glue stretch and shrink, possibly
followed by the name of finite units:

\Y\P\4\&{procedure}\1\  \37$\\{print\_glue}(\|d:\\{scaled};\,\35\\{order}:%
\\{integer};\,\35\|s:\\{str\_number})$;\C{prints a glue component}\2\6
\&{begin} \37$\\{print\_scaled}(\|d)$;\6
\&{if} $(\\{order}<\\{normal})\V(\\{order}>\\{filll})$ \1\&{then}\5
$\\{print}(\.{"foul"})$\6
\4\&{else} \&{if} $\\{order}>\\{normal}$ \1\&{then}\6
\&{begin} \37$\\{print}(\.{"fil"})$;\6
\&{while} $\\{order}>\\{fil}$ \1\&{do}\6
\&{begin} \37$\\{print\_char}(\.{"l"})$;\5
$\\{decr}(\\{order})$;\6
\&{end};\2\6
\&{end}\6
\4\&{else} \&{if} $\|s\I0$ \1\&{then}\5
$\\{print}(\|s)$;\2\2\2\6
\&{end};\par
\fi

\M178. The next subroutine prints a whole glue specification.

\Y\P\4\&{procedure}\1\  \37$\\{print\_spec}(\|p:\\{integer};\,\35\|s:\\{str%
\_number})$;\C{prints a glue specification}\2\6
\&{begin} \37\&{if} $(\|p<\\{mem\_min})\V(\|p\G\\{lo\_mem\_max})$ \1\&{then}\5
$\\{print\_char}(\.{"*"})$\6
\4\&{else} \&{begin} \37$\\{print\_scaled}(\\{width}(\|p))$;\6
\&{if} $\|s\I0$ \1\&{then}\5
$\\{print}(\|s)$;\2\6
\&{if} $\\{stretch}(\|p)\I0$ \1\&{then}\6
\&{begin} \37$\\{print}(\.{"\ plus\ "})$;\5
$\\{print\_glue}(\\{stretch}(\|p),\39\\{stretch\_order}(\|p),\39\|s)$;\6
\&{end};\2\6
\&{if} $\\{shrink}(\|p)\I0$ \1\&{then}\6
\&{begin} \37$\\{print}(\.{"\ minus\ "})$;\5
$\\{print\_glue}(\\{shrink}(\|p),\39\\{shrink\_order}(\|p),\39\|s)$;\6
\&{end};\2\6
\&{end};\2\6
\&{end};\par
\fi

\M179. We also need to declare some procedures that appear later in this
documentation.

\Y\P\X691:Declare procedures needed for displaying the elements of mlists\X\6
\X225:Declare the procedure called \\{print\_skip\_param}\X\par
\fi

\M180. Since boxes can be inside of boxes, \\{show\_node\_list} is inherently
recursive,
up to a given maximum number of levels.  The history of nesting is indicated
by the current string, which will be printed at the beginning of each line;
the length of this string, namely \\{cur\_length}, is the depth of nesting.

Recursive calls on \\{show\_node\_list} therefore use the following pattern:

\Y\P\D \37$\\{node\_list\_display}(\#)\S$\1\6
\&{begin} \37$\\{append\_char}(\.{"."})$;\5
$\\{show\_node\_list}(\#)$;\5
\\{flush\_char};\6
\&{end}\C{\\{str\_room} need not be checked; see \\{show\_box} below}\2\par
\fi

\M181. A global variable called \\{depth\_threshold} is used to record the
maximum
depth of nesting for which \\{show\_node\_list} will show information.  If we
have $\\{depth\_threshold}=0$, for example, only the top level information will
be given and no sublists will be traversed. Another global variable, called
\\{breadth\_max}, tells the maximum number of items to show at each level;
\\{breadth\_max} had better be positive, or you won't see anything.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{depth\_threshold}: \37\\{integer};\C{maximum nesting depth in box
displays}\6
\4\\{breadth\_max}: \37\\{integer};\C{maximum number of items shown at the same
list level}\par
\fi

\M182. Now we are ready for \\{show\_node\_list} itself. This procedure has
been
written to be ``extra robust'' in the sense that it should not crash or get
into a loop even if the data structures have been messed up by bugs in
the rest of the program. You can safely call its parent routine
$\\{show\_box}(\|p)$ for arbitrary values of \|p when you are debugging \TeX.
However, in the presence of bad data, the procedure may
fetch a \\{memory\_word} whose variant is different from the way it was stored;
for example, it might try to read $\\{mem}[\|p].\\{hh}$ when $\\{mem}[\|p]$
contains a scaled integer, if \|p is a pointer that has been
clobbered or chosen at random.

\Y\P\4\&{procedure}\1\  \37$\\{show\_node\_list}(\|p:\\{integer})$;\C{prints a
node list symbolically}\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37\|n: \37\\{integer};\C{the number of items already printed at this
level}\6
\|g: \37\\{real};\C{a glue ratio, as a floating point number}\2\6
\&{begin} \37\&{if} $\\{cur\_length}>\\{depth\_threshold}$ \1\&{then}\6
\&{begin} \37\&{if} $\|p>\\{null}$ \1\&{then}\5
$\\{print}(\.{"\ []"})$;\C{indicate that there's been some truncation}\2\6
\&{return};\6
\&{end};\2\6
$\|n\K0$;\6
\&{while} $\|p>\\{mem\_min}$ \1\&{do}\6
\&{begin} \37\\{print\_ln};\5
\\{print\_current\_string};\C{display the nesting history}\6
\&{if} $\|p>\\{mem\_end}$ \1\&{then}\C{pointer out of range}\6
\&{begin} \37$\\{print}(\.{"Bad\ link,\ display\ aborted."})$;\5
\&{return};\6
\&{end};\2\6
$\\{incr}(\|n)$;\6
\&{if} $\|n>\\{breadth\_max}$ \1\&{then}\C{time to stop}\6
\&{begin} \37$\\{print}(\.{"etc."})$;\5
\&{return};\6
\&{end};\2\6
\X183\*:Display node \|p\X;\6
$\|p\K\\{link}(\|p)$;\6
\&{end};\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M183\*. \P$\X183\*:Display node \|p\X\S$\6
\&{if} $\\{is\_char\_node}(\|p)$ \1\&{then}\6
\&{begin} \37$\\{print\_font\_and\_char}(\|p)$;\5
$\\{bypass\_xchar}(\|p)$;\6
\&{end}\6
\4\&{else} \&{case} $\\{type}(\|p)$ \1\&{of}\6
\4$\\{hlist\_node},\39\\{vlist\_node},\39\\{unset\_node}$: \37\X184:Display box
\|p\X;\6
\4\\{rule\_node}: \37\X187:Display rule \|p\X;\6
\4\\{ins\_node}: \37\X188:Display insertion \|p\X;\6
\4\\{whatsit\_node}: \37\X1356:Display the whatsit node \|p\X;\6
\4\\{glue\_node}: \37\X189:Display glue \|p\X;\6
\4\\{kern\_node}: \37\X191:Display kern \|p\X;\6
\4\\{math\_node}: \37\X192:Display math node \|p\X;\6
\4\\{ligature\_node}: \37\X193:Display ligature \|p\X;\6
\4\\{penalty\_node}: \37\X194:Display penalty \|p\X;\6
\4\\{disc\_node}: \37\X195:Display discretionary \|p\X;\6
\4\\{mark\_node}: \37\X196:Display mark \|p\X;\6
\4\\{adjust\_node}: \37\X197:Display adjustment \|p\X;\6
\hbox{\4}\X690:Cases of \\{show\_node\_list} that arise in mlists only\X\6
\4\&{othercases} \37$\\{print}(\.{"Unknown\ node\ type!"})$\2\6
\&{endcases}\2\par
\U section~182.\fi

\M184. \P$\X184:Display box \|p\X\S$\6
\&{begin} \37\&{if} $\\{type}(\|p)=\\{hlist\_node}$ \1\&{then}\5
$\\{print\_esc}(\.{"h"})$\6
\4\&{else} \&{if} $\\{type}(\|p)=\\{vlist\_node}$ \1\&{then}\5
$\\{print\_esc}(\.{"v"})$\6
\4\&{else} $\\{print\_esc}(\.{"unset"})$;\2\2\6
$\\{print}(\.{"box("})$;\5
$\\{print\_scaled}(\\{height}(\|p))$;\5
$\\{print\_char}(\.{"+"})$;\5
$\\{print\_scaled}(\\{depth}(\|p))$;\5
$\\{print}(\.{")x"})$;\5
$\\{print\_scaled}(\\{width}(\|p))$;\6
\&{if} $\\{type}(\|p)=\\{unset\_node}$ \1\&{then}\5
\X185:Display special fields of the unset node \|p\X\6
\4\&{else} \&{begin} \37\X186:Display the value of $\\{glue\_set}(\|p)$\X;\6
\&{if} $\\{shift\_amount}(\|p)\I0$ \1\&{then}\6
\&{begin} \37$\\{print}(\.{",\ shifted\ "})$;\5
$\\{print\_scaled}(\\{shift\_amount}(\|p))$;\6
\&{end};\2\6
\&{end};\2\6
$\\{node\_list\_display}(\\{list\_ptr}(\|p))$;\C{recursive call}\6
\&{end}\par
\U section~183\*.\fi

\M185. \P$\X185:Display special fields of the unset node \|p\X\S$\6
\&{begin} \37\&{if} $\\{span\_count}(\|p)\I\\{min\_quarterword}$ \1\&{then}\6
\&{begin} \37$\\{print}(\.{"\ ("})$;\5
$\\{print\_int}(\\{qo}(\\{span\_count}(\|p))+1)$;\5
$\\{print}(\.{"\ columns)"})$;\6
\&{end};\2\6
\&{if} $\\{glue\_stretch}(\|p)\I0$ \1\&{then}\6
\&{begin} \37$\\{print}(\.{",\ stretch\ "})$;\5
$\\{print\_glue}(\\{glue\_stretch}(\|p),\39\\{glue\_order}(\|p),\390)$;\6
\&{end};\2\6
\&{if} $\\{glue\_shrink}(\|p)\I0$ \1\&{then}\6
\&{begin} \37$\\{print}(\.{",\ shrink\ "})$;\5
$\\{print\_glue}(\\{glue\_shrink}(\|p),\39\\{glue\_sign}(\|p),\390)$;\6
\&{end};\2\6
\&{end}\par
\U section~184.\fi

\M186. The code will have to change in this place if \\{glue\_ratio} is
a structured type instead of an ordinary \\{real}. Note that this routine
should avoid arithmetic errors even if the \\{glue\_set} field holds an
arbitrary random value. The following code assumes that a properly
formed nonzero \\{real} number has absolute value $2↑{20}$ or more when
it is regarded as an integer; this precaution was adequate to prevent
floating point underflow on the author's computer.

\Y\P$\4\X186:Display the value of $\\{glue\_set}(\|p)$\X\S$\6
$\|g\K\\{float}(\\{glue\_set}(\|p))$;\6
\&{if} $(\|g\I\\{float\_constant}(0))\W(\\{glue\_sign}(\|p)\I\\{normal})$ \1%
\&{then}\6
\&{begin} \37$\\{print}(\.{",\ glue\ set\ "})$;\6
\&{if} $\\{glue\_sign}(\|p)=\\{shrinking}$ \1\&{then}\5
$\\{print}(\.{"-\ "})$;\2\6
\&{if} $\\{abs}(\\{mem}[\|p+\\{glue\_offset}].\\{int})<\O{4000000}$ \1\&{then}\5
$\\{print}(\.{"?.?"})$\6
\4\&{else} \&{if} $\\{abs}(\|g)>\\{float\_constant}(20000)$ \1\&{then}\6
\&{begin} \37\&{if} $\|g>\\{float\_constant}(0)$ \1\&{then}\5
$\\{print\_char}(\.{">"})$\6
\4\&{else} $\\{print}(\.{"<\ -"})$;\2\6
$\\{print\_glue}(20000\ast\\{unity},\39\\{glue\_order}(\|p),\390)$;\6
\&{end}\6
\4\&{else} $\\{print\_glue}(\\{round}(\\{unity}\ast\|g),\39\\{glue\_order}(%
\|p),\390)$;\2\2\6
\&{end}\2\par
\U section~184.\fi

\M187. \P$\X187:Display rule \|p\X\S$\6
\&{begin} \37$\\{print\_esc}(\.{"rule("})$;\5
$\\{print\_rule\_dimen}(\\{height}(\|p))$;\5
$\\{print\_char}(\.{"+"})$;\5
$\\{print\_rule\_dimen}(\\{depth}(\|p))$;\5
$\\{print}(\.{")x"})$;\5
$\\{print\_rule\_dimen}(\\{width}(\|p))$;\6
\&{end}\par
\U section~183\*.\fi

\M188. \P$\X188:Display insertion \|p\X\S$\6
\&{begin} \37$\\{print\_esc}(\.{"insert"})$;\5
$\\{print\_int}(\\{qo}(\\{subtype}(\|p)))$;\5
$\\{print}(\.{",\ natural\ size\ "})$;\5
$\\{print\_scaled}(\\{height}(\|p))$;\5
$\\{print}(\.{";\ split("})$;\5
$\\{print\_spec}(\\{split\_top\_ptr}(\|p),\390)$;\5
$\\{print\_char}(\.{","})$;\5
$\\{print\_scaled}(\\{depth}(\|p))$;\5
$\\{print}(\.{");\ float\ cost\ "})$;\5
$\\{print\_int}(\\{float\_cost}(\|p))$;\5
$\\{node\_list\_display}(\\{ins\_ptr}(\|p))$;\C{recursive call}\6
\&{end}\par
\U section~183\*.\fi

\M189. \P$\X189:Display glue \|p\X\S$\6
\&{if} $\\{subtype}(\|p)\G\\{a\_leaders}$ \1\&{then}\5
\X190:Display leaders \|p\X\6
\4\&{else} \&{begin} \37$\\{print\_esc}(\.{"glue"})$;\6
\&{if} $\\{subtype}(\|p)\I\\{normal}$ \1\&{then}\6
\&{begin} \37$\\{print\_char}(\.{"("})$;\6
\&{if} $\\{subtype}(\|p)<\\{cond\_math\_glue}$ \1\&{then}\5
$\\{print\_skip\_param}(\\{subtype}(\|p)-1)$\6
\4\&{else} \&{if} $\\{subtype}(\|p)=\\{cond\_math\_glue}$ \1\&{then}\5
$\\{print\_esc}(\.{"nonscript"})$\6
\4\&{else} $\\{print\_esc}(\.{"mskip"})$;\2\2\6
$\\{print\_char}(\.{")"})$;\6
\&{end};\2\6
\&{if} $\\{subtype}(\|p)\I\\{cond\_math\_glue}$ \1\&{then}\6
\&{begin} \37$\\{print\_char}(\.{"\ "})$;\6
\&{if} $\\{subtype}(\|p)<\\{cond\_math\_glue}$ \1\&{then}\5
$\\{print\_spec}(\\{glue\_ptr}(\|p),\390)$\6
\4\&{else} $\\{print\_spec}(\\{glue\_ptr}(\|p),\39\.{"mu"})$;\2\6
\&{end};\2\6
\&{end}\2\par
\U section~183\*.\fi

\M190. \P$\X190:Display leaders \|p\X\S$\6
\&{begin} \37$\\{print\_esc}(\.{""})$;\6
\&{if} $\\{subtype}(\|p)=\\{c\_leaders}$ \1\&{then}\5
$\\{print\_char}(\.{"c"})$\6
\4\&{else} \&{if} $\\{subtype}(\|p)=\\{x\_leaders}$ \1\&{then}\5
$\\{print\_char}(\.{"x"})$;\2\2\6
$\\{print}(\.{"leaders\ "})$;\5
$\\{print\_spec}(\\{glue\_ptr}(\|p),\390)$;\5
$\\{node\_list\_display}(\\{leader\_ptr}(\|p))$;\C{recursive call}\6
\&{end}\par
\U section~189.\fi

\M191. An ``explicit'' kern value is indicated implicitly by an explicit space.

\Y\P$\4\X191:Display kern \|p\X\S$\6
\&{if} $\\{subtype}(\|p)\I\\{mu\_glue}$ \1\&{then}\6
\&{begin} \37$\\{print\_esc}(\.{"kern"})$;\6
\&{if} $\\{subtype}(\|p)\I\\{normal}$ \1\&{then}\5
$\\{print\_char}(\.{"\ "})$;\2\6
$\\{print\_scaled}(\\{width}(\|p))$;\6
\&{if} $\\{subtype}(\|p)=\\{acc\_kern}$ \1\&{then}\5
$\\{print}(\.{"\ (for\ accent)"})$;\2\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{print\_esc}(\.{"mkern"})$;\5
$\\{print\_scaled}(\\{width}(\|p))$;\5
$\\{print}(\.{"mu"})$;\6
\&{end}\2\par
\U section~183\*.\fi

\M192. \P$\X192:Display math node \|p\X\S$\6
\&{begin} \37$\\{print\_esc}(\.{"math"})$;\6
\&{if} $\\{subtype}(\|p)=\\{before}$ \1\&{then}\5
$\\{print}(\.{"on"})$\6
\4\&{else} $\\{print}(\.{"off"})$;\2\6
\&{if} $\\{width}(\|p)\I0$ \1\&{then}\6
\&{begin} \37$\\{print}(\.{",\ surrounded\ "})$;\5
$\\{print\_scaled}(\\{width}(\|p))$;\6
\&{end};\2\6
\&{end}\par
\U section~183\*.\fi

\M193. \P$\X193:Display ligature \|p\X\S$\6
\&{begin} \37$\\{print\_font\_and\_char}(\\{lig\_char}(\|p))$;\5
$\\{print}(\.{"\ (ligature\ "})$;\5
$\\{font\_in\_short\_display}\K\\{font}(\\{lig\_char}(\|p))$;\5
$\\{short\_display}(\\{lig\_ptr}(\|p))$;\5
$\\{print\_char}(\.{")"})$;\6
\&{end}\par
\U section~183\*.\fi

\M194. \P$\X194:Display penalty \|p\X\S$\6
\&{begin} \37$\\{print\_esc}(\.{"penalty\ "})$;\5
$\\{print\_int}(\\{penalty}(\|p))$;\6
\&{end}\par
\U section~183\*.\fi

\M195. The \\{post\_break} list of a discretionary node is indicated by a
prefixed
`\.{\char'174}' instead of the `\..' before the \\{pre\_break} list.

\Y\P$\4\X195:Display discretionary \|p\X\S$\6
\&{begin} \37$\\{print\_esc}(\.{"discretionary"})$;\6
\&{if} $\\{replace\_count}(\|p)>0$ \1\&{then}\6
\&{begin} \37$\\{print}(\.{"\ replacing\ "})$;\5
$\\{print\_int}(\\{replace\_count}(\|p))$;\6
\&{end};\2\6
$\\{node\_list\_display}(\\{pre\_break}(\|p))$;\C{recursive call}\6
$\\{append\_char}(\.{"|"})$;\5
$\\{show\_node\_list}(\\{post\_break}(\|p))$;\5
\\{flush\_char};\C{recursive call}\6
\&{end}\par
\U section~183\*.\fi

\M196. \P$\X196:Display mark \|p\X\S$\6
\&{begin} \37$\\{print\_esc}(\.{"mark"})$;\5
$\\{print\_mark}(\\{mark\_ptr}(\|p))$;\6
\&{end}\par
\U section~183\*.\fi

\M197. \P$\X197:Display adjustment \|p\X\S$\6
\&{begin} \37$\\{print\_esc}(\.{"vadjust"})$;\5
$\\{node\_list\_display}(\\{adjust\_ptr}(\|p))$;\C{recursive call}\6
\&{end}\par
\U section~183\*.\fi

\M198. The recursive machinery is started by calling \\{show\_box}.

\Y\P\4\&{procedure}\1\  \37$\\{show\_box}(\|p:\\{pointer})$;\2\6
\&{begin} \37\X236:Assign the values $\\{depth\_threshold}\K\\{show\_box%
\_depth}$ and $\\{breadth\_max}\K\\{show\_box\_breadth}$\X;\6
\&{if} $\\{breadth\_max}\L0$ \1\&{then}\5
$\\{breadth\_max}\K5$;\2\6
\&{if} $\\{pool\_ptr}+\\{depth\_threshold}\G\\{pool\_size}$ \1\&{then}\5
$\\{depth\_threshold}\K\\{pool\_size}-\\{pool\_ptr}-1$;\C{now there's enough
room for prefix string}\2\6
$\\{show\_node\_list}(\|p)$;\C{the show starts at \|p}\6
\\{print\_ln};\6
\&{end};\par
\fi

\N199.  \[13] Destroying boxes.
When we are done with a node list, we are obliged to return it to free
storage, including all of its sublists. The recursive procedure
\\{flush\_node\_list} does this for us.

\fi

\M200. First, however, we shall consider two non-recursive procedures that do
simpler tasks. The first of these, \\{delete\_token\_ref}, is called when
a pointer to a token list's reference count is being removed. This means
that the token list should disappear if the reference count was \\{null},
otherwise the count should be decreased by one.

\Y\P\D \37$\\{token\_ref\_count}(\#)\S\\{info}(\#)$\C{reference count preceding
a token list}\par
\Y\P\4\&{procedure}\1\  \37$\\{delete\_token\_ref}(\|p:\\{pointer})$;\C{\|p
points to the reference count 	of a token list that is losing one reference}\2\6
\&{begin} \37\&{if} $\\{token\_ref\_count}(\|p)=\\{null}$ \1\&{then}\5
$\\{flush\_list}(\|p)$\6
\4\&{else} $\\{decr}(\\{token\_ref\_count}(\|p))$;\2\6
\&{end};\par
\fi

\M201. Similarly, \\{delete\_glue\_ref} is called when a pointer to a glue
specification is being withdrawn.
\Y\P\D \37$\\{fast\_delete\_glue\_ref}(\#)\S\hbox{}$\6
\&{begin} \37\&{if} $\\{glue\_ref\_count}(\#)=\\{null}$ \1\&{then}\5
$\\{free\_node}(\#,\39\\{glue\_spec\_size})$\6
\4\&{else} $\\{decr}(\\{glue\_ref\_count}(\#))$;\2\6
\&{end}\par
\Y\P\4\&{procedure}\1\  \37$\\{delete\_glue\_ref}(\|p:\\{pointer})$;\C{\|p
points to a glue specification}\6
$\\{fast\_delete\_glue\_ref}(\|p)$;\par
\fi

\M202. Now we are ready to delete any node list, recursively.
In practice, the nodes deleted are usually charnodes (about 2/3 of the time),
and they are glue nodes in about half of the remaining cases.

\Y\P\4\&{procedure}\1\  \37$\\{flush\_node\_list}(\|p:\\{pointer})$;\C{erase
list of nodes starting at \|p}\6
\4\&{label} \37\\{done};\C{go here when node \|p has been freed}\6
\4\&{var} \37\|q: \37\\{pointer};\C{successor to node \|p}\2\6
\&{begin} \37\&{while} $\|p\I\\{null}$ \1\&{do}\6
\&{begin} \37$\|q\K\\{link}(\|p)$;\6
\&{if} $\\{is\_char\_node}(\|p)$ \1\&{then}\5
$\\{free\_avail}(\|p)$\6
\4\&{else} \&{begin} \37\&{case} $\\{type}(\|p)$ \1\&{of}\6
\4$\\{hlist\_node},\39\\{vlist\_node},\39\\{unset\_node}$: \37\&{begin} \37$%
\\{flush\_node\_list}(\\{list\_ptr}(\|p))$;\5
$\\{free\_node}(\|p,\39\\{box\_node\_size})$;\5
\&{goto} \37\\{done};\6
\&{end};\6
\4\\{rule\_node}: \37\&{begin} \37$\\{free\_node}(\|p,\39\\{rule\_node%
\_size})$;\5
\&{goto} \37\\{done};\6
\&{end};\6
\4\\{ins\_node}: \37\&{begin} \37$\\{flush\_node\_list}(\\{ins\_ptr}(\|p))$;\5
$\\{delete\_glue\_ref}(\\{split\_top\_ptr}(\|p))$;\5
$\\{free\_node}(\|p,\39\\{ins\_node\_size})$;\5
\&{goto} \37\\{done};\6
\&{end};\6
\4\\{whatsit\_node}: \37\X1358:Wipe out the whatsit node \|p and \&{goto} %
\\{done}\X;\6
\4\\{glue\_node}: \37\&{begin} \37$\\{fast\_delete\_glue\_ref}(\\{glue\_ptr}(%
\|p))$;\6
\&{if} $\\{leader\_ptr}(\|p)\I\\{null}$ \1\&{then}\5
$\\{flush\_node\_list}(\\{leader\_ptr}(\|p))$;\2\6
\&{end};\6
\4$\\{kern\_node},\39\\{math\_node},\39\\{penalty\_node}$: \37\\{do\_nothing};\6
\4\\{ligature\_node}: \37$\\{flush\_node\_list}(\\{lig\_ptr}(\|p))$;\6
\4\\{mark\_node}: \37$\\{delete\_token\_ref}(\\{mark\_ptr}(\|p))$;\6
\4\\{disc\_node}: \37\&{begin} \37$\\{flush\_node\_list}(\\{pre\_break}(\|p))$;%
\5
$\\{flush\_node\_list}(\\{post\_break}(\|p))$;\6
\&{end};\6
\4\\{adjust\_node}: \37$\\{flush\_node\_list}(\\{adjust\_ptr}(\|p))$;\6
\hbox{\4}\X698:Cases of \\{flush\_node\_list} that arise in mlists only\X\6
\4\&{othercases} \37$\\{confusion}(\.{"flushing"})$\2\6
\&{endcases};\6
$\\{free\_node}(\|p,\39\\{small\_node\_size})$;\6
\4\\{done}: \37\&{end};\2\6
$\|p\K\|q$;\6
\&{end};\2\6
\&{end};\par
\fi

\N203.  \[14] Copying boxes.
Another recursive operation that acts on boxes is sometimes needed: The
procedure \\{copy\_node\_list} returns a pointer to another node list that has
the same structure and meaning as the original. Note that since glue
specifications and token lists have reference counts, we need not make
copies of them. Reference counts can never get too large to fit in a
halfword, since each pointer to a node is in a different memory address,
and the total number of memory addresses fits in a halfword.

(Well, there actually are also references from outside \\{mem}; if the
\\{save\_stack} is made arbitrarily large, it would theoretically be possible
to break \TeX\ by overflowing a reference count. But who would want to do
that?)

\Y\P\D \37$\\{add\_token\_ref}(\#)\S\\{incr}(\\{token\_ref\_count}(\#))$\C{new
reference to a token list}\par
\P\D \37$\\{add\_glue\_ref}(\#)\S\\{incr}(\\{glue\_ref\_count}(\#))$\C{new
reference to a glue spec}\par
\fi

\M204. The copying procedure copies words en masse without bothering
to look at their individual fields. If the node format changes---for
example, if the size is altered, or if some link field is moved to another
relative position---then this code may need to be changed too.

\Y\P\4\&{function}\1\  \37$\\{copy\_node\_list}(\|p:\\{pointer})$: \37%
\\{pointer};\C{makes a duplicate of the 	node list that starts at \|p and
returns a pointer to the new list}\6
\4\&{var} \37\|h: \37\\{pointer};\C{temporary head of copied list}\6
\|q: \37\\{pointer};\C{previous position in new list}\6
\|r: \37\\{pointer};\C{current node being fabricated for new list}\6
\\{words}: \37$0\to5$;\C{number of words remaining to be copied}\2\6
\&{begin} \37$\|h\K\\{get\_avail}$;\5
$\|q\K\|h$;\6
\&{while} $\|p\I\\{null}$ \1\&{do}\6
\&{begin} \37\X205:Make a copy of node \|p in node \|r\X;\6
$\\{link}(\|q)\K\|r$;\5
$\|q\K\|r$;\5
$\|p\K\\{link}(\|p)$;\6
\&{end};\2\6
$\\{link}(\|q)\K\\{null}$;\5
$\|q\K\\{link}(\|h)$;\5
$\\{free\_avail}(\|h)$;\5
$\\{copy\_node\_list}\K\|q$;\6
\&{end};\par
\fi

\M205. \P$\X205:Make a copy of node \|p in node \|r\X\S$\6
$\\{words}\K1$;\C{this setting occurs in more branches than any other}\6
\&{if} $\\{is\_char\_node}(\|p)$ \1\&{then}\5
$\|r\K\\{get\_avail}$\6
\4\&{else} \X206:Case statement to copy different types and set \\{words} to
the number of initial words not yet copied\X;\2\6
\&{while} $\\{words}>0$ \1\&{do}\6
\&{begin} \37$\\{decr}(\\{words})$;\5
$\\{mem}[\|r+\\{words}]\K\\{mem}[\|p+\\{words}]$;\6
\&{end}\2\par
\U section~204.\fi

\M206. \P$\X206:Case statement to copy different types and set \\{words} to the
number of initial words not yet copied\X\S$\6
\&{case} $\\{type}(\|p)$ \1\&{of}\6
\4$\\{hlist\_node},\39\\{vlist\_node},\39\\{unset\_node}$: \37\&{begin} \37$\|r%
\K\\{get\_node}(\\{box\_node\_size})$;\5
$\\{mem}[\|r+6]\K\\{mem}[\|p+6]$;\5
$\\{mem}[\|r+5]\K\\{mem}[\|p+5]$;\C{copy the last two words}\6
$\\{list\_ptr}(\|r)\K\\{copy\_node\_list}(\\{list\_ptr}(\|p))$;\C{this affects
$\\{mem}[\|r+5]$}\6
$\\{words}\K5$;\6
\&{end};\6
\4\\{rule\_node}: \37\&{begin} \37$\|r\K\\{get\_node}(\\{rule\_node\_size})$;\5
$\\{words}\K\\{rule\_node\_size}$;\6
\&{end};\6
\4\\{ins\_node}: \37\&{begin} \37$\|r\K\\{get\_node}(\\{ins\_node\_size})$;\5
$\\{mem}[\|r+4]\K\\{mem}[\|p+4]$;\5
$\\{add\_glue\_ref}(\\{split\_top\_ptr}(\|p))$;\5
$\\{ins\_ptr}(\|r)\K\\{copy\_node\_list}(\\{ins\_ptr}(\|p))$;\C{this affects $%
\\{mem}[\|r+4]$}\6
$\\{words}\K\\{ins\_node\_size}-1$;\6
\&{end};\6
\4\\{whatsit\_node}: \37\X1357:Make a partial copy of the whatsit node \|p and
make \|r point to it; set \\{words} to the number of initial words not yet
copied\X;\6
\4\\{glue\_node}: \37\&{begin} \37$\|r\K\\{get\_node}(\\{small\_node\_size})$;\5
$\\{add\_glue\_ref}(\\{glue\_ptr}(\|p))$;\5
$\\{glue\_ptr}(\|r)\K\\{glue\_ptr}(\|p)$;\5
$\\{leader\_ptr}(\|r)\K\\{copy\_node\_list}(\\{leader\_ptr}(\|p))$;\6
\&{end};\6
\4$\\{kern\_node},\39\\{math\_node},\39\\{penalty\_node}$: \37\&{begin} \37$\|r%
\K\\{get\_node}(\\{small\_node\_size})$;\5
$\\{words}\K\\{small\_node\_size}$;\6
\&{end};\6
\4\\{ligature\_node}: \37\&{begin} \37$\|r\K\\{get\_node}(\\{small\_node%
\_size})$;\5
$\\{mem}[\\{lig\_char}(\|r)]\K\\{mem}[\\{lig\_char}(\|p)]$;\C{copy \\{font} and
\\{character}}\6
$\\{lig\_ptr}(\|r)\K\\{copy\_node\_list}(\\{lig\_ptr}(\|p))$;\6
\&{end};\6
\4\\{disc\_node}: \37\&{begin} \37$\|r\K\\{get\_node}(\\{small\_node\_size})$;\5
$\\{pre\_break}(\|r)\K\\{copy\_node\_list}(\\{pre\_break}(\|p))$;\5
$\\{post\_break}(\|r)\K\\{copy\_node\_list}(\\{post\_break}(\|p))$;\6
\&{end};\6
\4\\{mark\_node}: \37\&{begin} \37$\|r\K\\{get\_node}(\\{small\_node\_size})$;\5
$\\{add\_token\_ref}(\\{mark\_ptr}(\|p))$;\5
$\\{words}\K\\{small\_node\_size}$;\6
\&{end};\6
\4\\{adjust\_node}: \37\&{begin} \37$\|r\K\\{get\_node}(\\{small\_node%
\_size})$;\5
$\\{adjust\_ptr}(\|r)\K\\{copy\_node\_list}(\\{adjust\_ptr}(\|p))$;\6
\&{end};\C{$\\{words}=1=\\{small\_node\_size}-1$}\6
\4\&{othercases} \37$\\{confusion}(\.{"copying"})$\2\6
\&{endcases}\par
\U section~205.\fi

\N207.  \[15] The command codes.
Before we can go any further, we need to define symbolic names for the internal
code numbers that represent the various commands obeyed by \TeX. These codes
are somewhat arbitrary, but not completely so. For example, the command
codes for character types are fixed by the language, since a user says,
e.g., `\.{\\catcode \`\\\${} = 3}' to make \.{\char'44} a math delimiter,
and the command code \\{math\_shift} is equal to~3. Some other codes have
been made adjacent so that   \&{case}  statements in the program need not
consider
cases that are widely spaced, or so that   \&{case}  statements can be replaced
by   \&{if}  statements.

At any rate, here is the list, for future reference. First come the
``catcode'' commands, several of which share their numeric codes with
ordinary commands when the catcode cannot emerge from \TeX's scanning routine.

\Y\P\D \37$\\{escape}=0$\C{escape delimiter (called \.\\ in {\sl The \TeX book%
\/})}\par
\P\D \37$\\{relax}=0$\C{do nothing ( \.{\\relax} )}\par
\P\D \37$\\{left\_brace}=1$\C{beginning of a group ( \.\{ )}\par
\P\D \37$\\{right\_brace}=2$\C{ending of a group ( \.\} )}\par
\P\D \37$\\{math\_shift}=3$\C{mathematics shift character ( \.\$ )}\par
\P\D \37$\\{tab\_mark}=4$\C{alignment delimiter ( \.\&, \.{\\span} )}\par
\P\D \37$\\{car\_ret}=5$\C{end of line ( \\{carriage\_return}, \.{\\cr}, \.{%
\\crcr} )}\par
\P\D \37$\\{out\_param}=5$\C{output a macro parameter}\par
\P\D \37$\\{mac\_param}=6$\C{macro parameter symbol ( \.\# )}\par
\P\D \37$\\{sup\_mark}=7$\C{superscript ( \.{\char'136} )}\par
\P\D \37$\\{sub\_mark}=8$\C{subscript ( \.{\char'137} )}\par
\P\D \37$\\{ignore}=9$\C{characters to ignore ( \.{\↑\↑J} )}\par
\P\D \37$\\{endv}=9$\C{end of \<v_j> list in alignment template}\par
\P\D \37$\\{spacer}=10$\C{characters equivalent to blank space ( \.{\ } )}\par
\P\D \37$\\{letter}=11$\C{characters regarded as letters ( \.{A..Z}, \.{a..z}
)}\par
\P\D \37$\\{other\_char}=12$\C{none of the special character types}\par
\P\D \37$\\{active\_char}=13$\C{characters that invoke macros ( \.{\↑\↑[} )}\par
\P\D \37$\\{par\_end}=13$\C{end of paragraph ( \.{\\par} )}\par
\P\D \37$\\{match}=13$\C{match a macro parameter}\par
\P\D \37$\\{comment}=14$\C{characters that introduce comments ( \.\% )}\par
\P\D \37$\\{end\_match}=14$\C{end of parameters to macro}\par
\P\D \37$\\{stop}=14$\C{end of job ( \.{\\end}, \.{\\dump} )}\par
\P\D \37$\\{invalid\_char}=15$\C{characters that shouldn't appear ( \.{\↑\↑?}
)}\par
\P\D \37$\\{delim\_num}=15$\C{specify delimiter numerically ( \.{\\delimiter}
)}\par
\P\D \37$\\{max\_char\_code}=15$\C{largest catcode for individual characters}%
\par
\fi

\M208\*. Next are the ordinary run-of-the-mill command codes.  Codes that are
\\{min\_internal} or more represent internal quantities that might be
expanded by `\.{\\the}'.

\Y\P\D \37$\\{char\_num}=16$\C{character specified numerically ( \.{\\char} )}%
\par
\P\D \37$\\{xchar\_num}=17$\C{extended character ( \.{\\xchar} )}\par
\P\D \37$\\{math\_char\_num}=18$\C{explicit math code ( \.{\\mathchar} )}\par
\P\D \37$\\{mark}=19$\C{mark definition ( \.{\\mark} )}\par
\P\D \37$\\{xray}=20$\C{peek inside of \TeX\ ( \.{\\show}, \.{\\showbox},
etc.~)}\par
\P\D \37$\\{make\_box}=21$\C{make a box ( \.{\\box}, \.{\\copy}, \.{\\hbox},
etc.~)}\par
\P\D \37$\\{hmove}=22$\C{horizontal motion ( \.{\\moveleft}, \.{\\moveright} )}%
\par
\P\D \37$\\{vmove}=23$\C{vertical motion ( \.{\\raise}, \.{\\lower} )}\par
\P\D \37$\\{un\_hbox}=24$\C{unglue a box ( \.{\\unhbox}, \.{\\unhcopy} )}\par
\P\D \37$\\{un\_vbox}=25$\C{unglue a box ( \.{\\unvbox}, \.{\\unvcopy} )}\par
\P\D \37$\\{remove\_item}=26$\C{nullify last item ( \.{\\unpenalty}, 	\.{%
\\unkern}, \.{\\unskip} )}\par
\P\D \37$\\{hskip}=27$\C{horizontal glue ( \.{\\hskip}, \.{\\hfil}, etc.~)}\par
\P\D \37$\\{vskip}=28$\C{vertical glue ( \.{\\vskip}, \.{\\vfil}, etc.~)}\par
\P\D \37$\\{mskip}=29$\C{math glue ( \.{\\mskip} )}\par
\P\D \37$\\{kern}=30$\C{fixed space ( \.{\\kern})}\par
\P\D \37$\\{mkern}=31$\C{math kern ( \.{\\mkern} )}\par
\P\D \37$\\{leader\_ship}=32$\C{use a box ( \.{\\shipout}, \.{\\leaders},
etc.~)}\par
\P\D \37$\\{halign}=33$\C{horizontal table alignment ( \.{\\halign} )}\par
\P\D \37$\\{valign}=34$\C{vertical table alignment ( \.{\\valign} )}\par
\P\D \37$\\{no\_align}=35$\C{temporary escape from alignment ( \.{\\noalign} )}%
\par
\P\D \37$\\{vrule}=36$\C{vertical rule ( \.{\\vrule} )}\par
\P\D \37$\\{hrule}=37$\C{horizontal rule ( \.{\\hrule} )}\par
\P\D \37$\\{insert}=38$\C{vlist inserted in box ( \.{\\insert} )}\par
\P\D \37$\\{vadjust}=39$\C{vlist inserted in enclosing paragraph ( \.{%
\\vadjust} )}\par
\P\D \37$\\{ignore\_spaces}=40$\C{gobble \\{spacer} tokens ( \.{\\ignorespaces}
)}\par
\P\D \37$\\{after\_assignment}=41$\C{save till assignment is done ( \.{%
\\afterassignment} )}\par
\P\D \37$\\{after\_group}=42$\C{save till group is done ( \.{\\aftergroup} )}%
\par
\P\D \37$\\{break\_penalty}=43$\C{additional badness ( \.{\\penalty} )}\par
\P\D \37$\\{start\_par}=44$\C{begin paragraph ( \.{\\indent}, \.{\\noindent} )}%
\par
\P\D \37$\\{ital\_corr}=45$\C{italic correction ( \.{\\/} )}\par
\P\D \37$\\{accent}=46$\C{attach accent in text ( \.{\\accent} )}\par
\P\D \37$\\{math\_accent}=47$\C{attach accent in math ( \.{\\mathaccent} )}\par
\P\D \37$\\{discretionary}=48$\C{discretionary texts ( \.{\\-}, \.{%
\\discretionary} )}\par
\P\D \37$\\{eq\_no}=49$\C{equation number ( \.{\\eqno}, \.{\\leqno} )}\par
\P\D \37$\\{left\_right}=50$\C{variable delimiter ( \.{\\left}, \.{\\right} )}%
\par
\P\D \37$\\{math\_comp}=51$\C{component of formula ( \.{\\mathbin}, etc.~)}\par
\P\D \37$\\{limit\_switch}=52$\C{diddle limit conventions ( \.{%
\\displaylimits}, etc.~)}\par
\P\D \37$\\{above}=53$\C{generalized fraction ( \.{\\above}, \.{\\atop},
etc.~)}\par
\P\D \37$\\{math\_style}=54$\C{style specification ( \.{\\displaystyle},
etc.~)}\par
\P\D \37$\\{math\_choice}=55$\C{choice specification ( \.{\\mathchoice} )}\par
\P\D \37$\\{non\_script}=56$\C{conditional math glue ( \.{\\nonscript} )}\par
\P\D \37$\\{vcenter}=57$\C{vertically center a vbox ( \.{\\vcenter} )}\par
\P\D \37$\\{case\_shift}=58$\C{force specific case ( \.{\\lowercase}, \.{%
\\uppercase}~)}\par
\P\D \37$\\{message}=59$\C{send to user ( \.{\\message}, \.{\\errmessage} )}\par
\P\D \37$\\{extension}=60$\C{extensions to \TeX\ ( \.{\\write}, \.{\\special},
etc.~)}\par
\P\D \37$\\{in\_stream}=61$\C{files for reading ( \.{\\openin}, \.{\\closein}
)}\par
\P\D \37$\\{begin\_group}=62$\C{begin local grouping ( \.{\\begingroup} )}\par
\P\D \37$\\{end\_group}=63$\C{end local grouping ( \.{\\endgroup} )}\par
\P\D \37$\\{omit}=64$\C{omit alignment template ( \.{\\omit} )}\par
\P\D \37$\\{ex\_space}=65$\C{explicit space ( \.{\\\ } )}\par
\P\D \37$\\{radical}=66$\C{square root and similar signs ( \.{\\radical} )}\par
\P\D \37$\\{end\_cs\_name}=67$\C{end control sequence ( \.{\\endcsname} )}\par
\P\D \37$\\{min\_internal}=68$\C{the smallest code that can follow \.{\\the}}%
\par
\P\D \37$\\{char\_given}=68$\C{character code defined by \.{\\chardef}}\par
\P\D \37$\\{math\_given}=69$\C{math code defined by \.{\\mathchardef}}\par
\P\D \37$\\{last\_item}=70$\C{most recent item ( \.{\\lastpenalty}, 	\.{%
\\lastkern}, \.{\\lastskip} )}\par
\P\D \37$\\{max\_non\_prefixed\_command}=70$\C{largest command code that can't
be \.{\\global}}\par
\fi

\M209\*. The next codes are special; they all relate to mode-independent
assignment of values to \TeX's internal registers or tables.
Codes that are \\{max\_internal} or less represent internal quantities
that might be expanded by `\.{\\the}'.

\Y\P\D \37$\\{toks\_register}=71$\C{token list register ( \.{\\toks} )}\par
\P\D \37$\\{assign\_toks}=72$\C{special token list ( \.{\\output}, \.{%
\\everypar}, etc.~)}\par
\P\D \37$\\{assign\_int}=73$\C{user-defined integer ( \.{\\tolerance}, \.{%
\\day}, etc.~)}\par
\P\D \37$\\{assign\_dimen}=74$\C{user-defined length ( \.{\\hsize}, etc.~)}\par
\P\D \37$\\{assign\_glue}=75$\C{user-defined glue ( \.{\\baselineskip}, etc.~)}%
\par
\P\D \37$\\{assign\_mu\_glue}=76$\C{user-defined muglue ( \.{\\thinmuskip},
etc.~)}\par
\P\D \37$\\{assign\_font\_dimen}=77$\C{user-defined font dimension ( \.{%
\\fontdimen} )}\par
\P\D \37$\\{assign\_font\_int}=78$\C{user-defined font integer ( \.{%
\\hyphenchar}, 	\.{\\skewchar} )}\par
\P\D \37$\\{set\_aux}=79$\C{specify state info ( \.{\\spacefactor}, \.{%
\\prevdepth} )}\par
\P\D \37$\\{set\_prev\_graf}=80$\C{specify state info ( \.{\\prevgraf} )}\par
\P\D \37$\\{set\_page\_dimen}=81$\C{specify state info ( \.{\\pagegoal},
etc.~)}\par
\P\D \37$\\{set\_page\_int}=82$\C{specify state info ( \.{\\deadcycles}, 	\.{%
\\insertpenalties} )}\par
\P\D \37$\\{set\_box\_dimen}=83$\C{change dimension of box ( \.{\\wd}, \.{%
\\ht}, \.{\\dp} )}\par
\P\D \37$\\{set\_shape}=84$\C{specify fancy paragraph shape ( \.{\\parshape} )}%
\par
\P\D \37$\\{def\_code}=85$\C{define a character code ( \.{\\catcode}, etc.~)}%
\par
\P\D \37$\\{def\_family}=86$\C{declare math fonts ( \.{\\textfont}, etc.~)}\par
\P\D \37$\\{set\_font}=87$\C{set current font ( font identifiers )}\par
\P\D \37$\\{def\_font}=88$\C{define a font file ( \.{\\font} )}\par
\P\D \37$\\{register}=89$\C{internal register ( \.{\\count}, \.{\\dimen},
etc.~)}\par
\P\D \37$\\{max\_internal}=89$\C{the largest code that can follow \.{\\the}}\par
\P\D \37$\\{advance}=90$\C{advance a register or parameter ( \.{\\advance} )}%
\par
\P\D \37$\\{multiply}=91$\C{multiply a register or parameter ( \.{\\multiply}
)}\par
\P\D \37$\\{divide}=92$\C{divide a register or parameter ( \.{\\divide} )}\par
\P\D \37$\\{prefix}=93$\C{qualify a definition ( \.{\\global}, \.{\\long}, \.{%
\\outer} )}\par
\P\D \37$\\{let}=94$\C{assign a command code ( \.{\\let}, \.{\\futurelet} )}\par
\P\D \37$\\{shorthand\_def}=95$\C{code definition ( \.{\\chardef}, \.{%
\\countdef}, etc.~)}\par
\P\D \37$\\{read\_to\_cs}=96$\C{read into a control sequence ( \.{\\read} )}\par
\P\D \37$\\{def}=97$\C{macro definition ( \.{\\def}, \.{\\gdef}, \.{\\xdef}, %
\.{\\edef} )}\par
\P\D \37$\\{set\_box}=98$\C{set a box ( \.{\\setbox} )}\par
\P\D \37$\\{hyph\_data}=99$\C{hyphenation data ( \.{\\hyphenation}, \.{%
\\patterns} )}\par
\P\D \37$\\{set\_interaction}=100$\C{define level of interaction ( \.{%
\\batchmode}, etc.~)}\par
\P\D \37$\\{max\_command}=100$\C{the largest command code seen at \\{big%
\_switch}}\par
\fi

\M210. The remaining command codes are extra special, since they cannot get
through
\TeX's scanner to the main control routine. They have been given values higher
than \\{max\_command} so that their special nature is easily discernible.
The ``expandable'' commands come first.

\Y\P\D \37$\\{undefined\_cs}=\\{max\_command}+1$\C{initial state of most \\{eq%
\_type} fields}\par
\P\D \37$\\{expand\_after}=\\{max\_command}+2$\C{special expansion ( \.{%
\\expandafter} )}\par
\P\D \37$\\{no\_expand}=\\{max\_command}+3$\C{special nonexpansion ( \.{%
\\noexpand} )}\par
\P\D \37$\\{input}=\\{max\_command}+4$\C{input a source file ( \.{\\input}, \.{%
\\endinput} )}\par
\P\D \37$\\{if\_test}=\\{max\_command}+5$\C{conditional text ( \.{\\if}, \.{%
\\ifcase}, etc.~)}\par
\P\D \37$\\{fi\_or\_else}=\\{max\_command}+6$\C{delimiters for conditionals ( %
\.{\\else}, etc.~)}\par
\P\D \37$\\{cs\_name}=\\{max\_command}+7$\C{make a control sequence from tokens
( \.{\\csname} )}\par
\P\D \37$\\{convert}=\\{max\_command}+8$\C{convert to text ( \.{\\number}, \.{%
\\string}, etc.~)}\par
\P\D \37$\\{the}=\\{max\_command}+9$\C{expand an internal quantity ( \.{\\the}
)}\par
\P\D \37$\\{top\_bot\_mark}=\\{max\_command}+10$\C{inserted mark ( \.{%
\\topmark}, etc.~)}\par
\P\D \37$\\{call}=\\{max\_command}+11$\C{non-long, non-outer control sequence}%
\par
\P\D \37$\\{long\_call}=\\{max\_command}+12$\C{long, non-outer control
sequence}\par
\P\D \37$\\{outer\_call}=\\{max\_command}+13$\C{non-long, outer control
sequence}\par
\P\D \37$\\{long\_outer\_call}=\\{max\_command}+14$\C{long, outer control
sequence}\par
\P\D \37$\\{end\_template}=\\{max\_command}+15$\C{end of an alignment template}%
\par
\P\D \37$\\{dont\_expand}=\\{max\_command}+16$\C{the following token was marked
by \.{\\noexpand}}\par
\P\D \37$\\{glue\_ref}=\\{max\_command}+17$\C{the equivalent points to a glue
specification}\par
\P\D \37$\\{shape\_ref}=\\{max\_command}+18$\C{the equivalent points to a
parshape specification}\par
\P\D \37$\\{box\_ref}=\\{max\_command}+19$\C{the equivalent points to a box
node, or is \\{null}}\par
\P\D \37$\\{data}=\\{max\_command}+20$\C{the equivalent is simply a halfword
number}\par
\fi

\N211.  \[16] The semantic nest.
\TeX\ is typically in the midst of building many lists at once. For example,
when a math formula is being processed, \TeX\ is in math mode and
working on an mlist; this formula has temporarily interrupted \TeX\ from
being in horizontal mode and building the hlist of a paragraph; and this
paragraph has temporarily interrupted \TeX\ from being in vertical mode
and building the vlist for the next page of a document. Similarly, when a
\.{\\vbox} occurs inside of an \.{\\hbox}, \TeX\ is temporarily
interrupted from working in restricted horizontal mode, and it enters
internal vertical mode.  The ``semantic nest'' is a stack that
keeps track of what lists and modes are currently suspended.

At each level of processing we are in one of six modes:

\yskip\hang\\{vmode} stands for vertical mode (the page builder);

\hang\\{hmode} stands for horizontal mode (the paragraph builder);

\hang\\{mmode} stands for displayed formula mode;

\hang$-\\{vmode}$ stands for internal vertical mode (e.g., in a \.{\\vbox});

\hang$-\\{hmode}$ stands for restricted horizontal mode (e.g., in an \.{%
\\hbox});

\hang$-\\{mmode}$ stands for math formula mode (not displayed).

\yskip\noindent The mode is temporarily set to zero while processing \.{%
\\write}
texts in the \\{ship\_out} routine.

Numeric values are assigned to \\{vmode}, \\{hmode}, and \\{mmode} so that
\TeX's ``big semantic switch'' can select the appropriate thing to
do by computing the value $\\{abs}(\\{mode})+\\{cur\_cmd}$, where \\{mode} is
the current
mode and \\{cur\_cmd} is the current command code.

\Y\P\D \37$\\{vmode}=1$\C{vertical mode}\par
\P\D \37$\\{hmode}=\\{vmode}+\\{max\_command}+1$\C{horizontal mode}\par
\P\D \37$\\{mmode}=\\{hmode}+\\{max\_command}+1$\C{math mode}\par
\Y\P\4\&{procedure}\1\  \37$\\{print\_mode}(\|m:\\{integer})$;\C{prints the
mode represented by \|m}\2\6
\&{begin} \37\&{if} $\|m>0$ \1\&{then}\6
\&{case} $\|m\mathbin{\&{div}}(\\{max\_command}+1)$ \1\&{of}\6
\40: \37$\\{print}(\.{"vertical"})$;\6
\41: \37$\\{print}(\.{"horizontal"})$;\6
\42: \37$\\{print}(\.{"display\ math"})$;\2\6
\&{end}\6
\4\&{else} \&{if} $\|m=0$ \1\&{then}\5
$\\{print}(\.{"no"})$\6
\4\&{else} \&{case} $(-\|m)\mathbin{\&{div}}(\\{max\_command}+1)$ \1\&{of}\6
\40: \37$\\{print}(\.{"internal\ vertical"})$;\6
\41: \37$\\{print}(\.{"restricted\ horizontal"})$;\6
\42: \37$\\{print}(\.{"math"})$;\2\6
\&{end};\2\2\6
$\\{print}(\.{"\ mode"})$;\6
\&{end};\par
\fi

\M212. The state of affairs at any semantic level can be represented by
five values:

\yskip\hang\\{mode} is the number representing the semantic mode, as
just explained.

\yskip\hang\\{head} is a \\{pointer} to a list head for the list being built;
$\\{link}(\\{head})$ therefore points to the first element of the list, or
to \\{null} if the list is empty.

\yskip\hang\\{tail} is a \\{pointer} to the final node of the list being
built; thus, $\\{tail}=\\{head}$ if and only if the list is empty.

\yskip\hang\\{prev\_graf} is the number of lines of the current paragraph that
have already been put into the present vertical list.

\yskip\hang\\{aux} is an auxiliary integer that gives further information
that is needed to characterize the situation.

\yskip\noindent
In vertical mode, \\{aux} is also known as \\{prev\_depth}; it is the scaled
value representing the depth of the previous box, for use in baseline
calculations, or it is $\L-1000$pt if the next box on the vertical list is to
be exempt from baseline calculations.  In horizontal mode, \\{aux} is also
known as \\{space\_factor}; it holds the current space factor used in spacing
calculations. In math mode, \\{aux} is also known as \\{incompleat\_noad}; if
not \\{null}, it points to a record that represents the numerator of a
generalized fraction for which the denominator is currently being formed
in the current list.

There is also a sixth quantity, \\{mode\_line}, which is used to correlate
the semantic nest with the user's input; \\{mode\_line} contains the source
line number at which the current level of nesting was entered. The negative
of this line number is used as the \\{mode\_line} at the level of the
user's output routine.

The semantic nest is an array called \\{nest} that holds the \\{mode}, %
\\{head},
\\{tail}, \\{prev\_graf}, \\{aux}, and \\{mode\_line} values for all semantic
levels
below the currently active one. Information about the currently active
level is kept in the global quantities \\{mode}, \\{head}, \\{tail}, \\{prev%
\_graf},
\\{aux}, and \\{mode\_line}, which live in a \PASCAL\ record that is ready to
be pushed onto \\{nest} if necessary.

\Y\P\D \37$\\{ignore\_depth}\S-65536000$\C{\\{prev\_depth} value that is
ignored}\par
\Y\P$\4\X18:Types in the outer block\X\mathrel{+}\S$\6
$\\{list\_state\_record}=$\1\5
\1\&{record} \37\\{mode\_field}: \37$-\\{mmode}\to\\{mmode}$;\6
\4$\\{head\_field},\39\\{tail\_field}$: \37\\{pointer};\6
\4$\\{pg\_field},\39\\{aux\_field},\39\\{ml\_field}$: \37\\{integer};\2\6
\&{end};\2\par
\fi

\M213. \P\D \37$\\{mode}\S\\{cur\_list}.\\{mode\_field}$\C{current mode}\par
\P\D \37$\\{head}\S\\{cur\_list}.\\{head\_field}$\C{header node of current
list}\par
\P\D \37$\\{tail}\S\\{cur\_list}.\\{tail\_field}$\C{final node on current list}%
\par
\P\D \37$\\{prev\_graf}\S\\{cur\_list}.\\{pg\_field}$\C{number of paragraph
lines accumulated}\par
\P\D \37$\\{aux}\S\\{cur\_list}.\\{aux\_field}$\C{auxiliary data about the
current list}\par
\P\D \37$\\{prev\_depth}\S\\{aux}$\C{the name of \\{aux} in vertical mode}\par
\P\D \37$\\{space\_factor}\S\\{aux}$\C{the name of \\{aux} in horizontal mode}%
\par
\P\D \37$\\{incompleat\_noad}\S\\{aux}$\C{the name of \\{aux} in math mode}\par
\P\D \37$\\{mode\_line}\S\\{cur\_list}.\\{ml\_field}$\C{source file line number
at beginning of list}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{nest}: \37\&{array} $[0\to\\{nest\_size}]$ \1\&{of}\5
\\{list\_state\_record};\2\6
\4\\{nest\_ptr}: \37$0\to\\{nest\_size}$;\C{first unused location of \\{nest}}\6
\4\\{max\_nest\_stack}: \37$0\to\\{nest\_size}$;\C{maximum of \\{nest\_ptr}
when pushing}\6
\4\\{cur\_list}: \37\\{list\_state\_record};\C{the ``top'' semantic state}\6
\4\\{shown\_mode}: \37$-\\{mmode}\to\\{mmode}$;\C{most recent mode shown by \.{%
\\tracingcommands}}\par
\fi

\M214. Here is a common way to make the current list grow:

\Y\P\D \37$\\{tail\_append}(\#)\S$\1\6
\&{begin} \37$\\{link}(\\{tail})\K\#$;\5
$\\{tail}\K\\{link}(\\{tail})$;\6
\&{end}\2\par
\fi

\M215. We will see later that the vertical list at the bottom semantic level is
split
into two parts; the ``current page'' runs from \\{page\_head} to \\{page%
\_tail},
and the ``contribution list'' runs from \\{contrib\_head} to \\{tail} of
semantic level zero. The idea is that contributions are first formed in
vertical mode, then ``contributed'' to the current page (during which time
the page-breaking decisions are made). For now, we don't need to know
any more details about the page-building process.

\Y\P$\4\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{nest\_ptr}\K0$;\5
$\\{max\_nest\_stack}\K0$;\5
$\\{mode}\K\\{vmode}$;\5
$\\{head}\K\\{contrib\_head}$;\5
$\\{tail}\K\\{contrib\_head}$;\5
$\\{prev\_depth}\K\\{ignore\_depth}$;\5
$\\{mode\_line}\K0$;\5
$\\{prev\_graf}\K0$;\5
$\\{shown\_mode}\K0$;\6
\X991:Start a new current page\X;\par
\fi

\M216. When \TeX's work on one level is interrupted, the state is saved by
calling \\{push\_nest}. This routine changes \\{head} and \\{tail} so that
a new (empty) list is begun; it does not change \\{mode} or \\{aux}.

\Y\P\4\&{procedure}\1\  \37\\{push\_nest};\C{enter a new semantic level, save
the old}\2\6
\&{begin} \37\&{if} $\\{nest\_ptr}>\\{max\_nest\_stack}$ \1\&{then}\6
\&{begin} \37$\\{max\_nest\_stack}\K\\{nest\_ptr}$;\6
\&{if} $\\{nest\_ptr}=\\{nest\_size}$ \1\&{then}\5
$\\{overflow}(\.{"semantic\ nest\ size"},\39\\{nest\_size})$;\2\6
\&{end};\2\6
$\\{nest}[\\{nest\_ptr}]\K\\{cur\_list}$;\C{stack the record}\6
$\\{incr}(\\{nest\_ptr})$;\5
$\\{head}\K\\{get\_avail}$;\5
$\\{tail}\K\\{head}$;\5
$\\{prev\_graf}\K0$;\5
$\\{mode\_line}\K\\{line}$;\6
\&{end};\par
\fi

\M217. Conversely, when \TeX\ is finished on the current level, the former
state is restored by calling \\{pop\_nest}. This routine will never be
called at the lowest semantic level, nor will it be called unless \\{head}
is a node that should be returned to free memory.

\Y\P\4\&{procedure}\1\  \37\\{pop\_nest};\C{leave a semantic level, re-enter
the old}\2\6
\&{begin} \37$\\{free\_avail}(\\{head})$;\5
$\\{decr}(\\{nest\_ptr})$;\5
$\\{cur\_list}\K\\{nest}[\\{nest\_ptr}]$;\6
\&{end};\par
\fi

\M218. Here is a procedure that displays what \TeX\ is working on, at all
levels.

\Y\P\4\&{procedure}\1\  \37\\{print\_totals};\5
\\{forward}; \hbox{\2} \6
\4\&{procedure}\1\  \37\\{show\_activities};\6
\4\&{var} \37\|p: \37$0\to\\{nest\_size}$;\C{index into \\{nest}}\6
\|m: \37$-\\{mmode}\to\\{mmode}$;\C{mode}\6
\|a: \37\\{integer};\C{auxiliary}\6
$\|q,\39\|r$: \37\\{pointer};\C{for showing the current page}\6
\|t: \37\\{integer};\C{ditto}\2\6
\&{begin} \37$\\{nest}[\\{nest\_ptr}]\K\\{cur\_list}$;\C{put the top level into
the array}\6
$\\{print\_nl}(\.{""})$;\5
\\{print\_ln};\6
\&{for} $\|p\K\\{nest\_ptr}\mathrel{\&{downto}}0$ \1\&{do}\6
\&{begin} \37$\|m\K\\{nest}[\|p].\\{mode\_field}$;\5
$\|a\K\\{nest}[\|p].\\{aux\_field}$;\5
$\\{print\_nl}(\.{"\#\#\#\ "})$;\5
$\\{print\_mode}(\|m)$;\5
$\\{print}(\.{"\ entered\ at\ line\ "})$;\5
$\\{print\_int}(\\{abs}(\\{nest}[\|p].\\{ml\_field}))$;\6
\&{if} $\\{nest}[\|p].\\{ml\_field}<0$ \1\&{then}\5
$\\{print}(\.{"\ (\\output\ routine)"})$;\2\6
\&{if} $\|p=0$ \1\&{then}\6
\&{begin} \37\X986:Show the status of the current page\X;\6
\&{if} $\\{link}(\\{contrib\_head})\I\\{null}$ \1\&{then}\5
$\\{print\_nl}(\.{"\#\#\#\ recent\ contributions:"})$;\2\6
\&{end};\2\6
$\\{show\_box}(\\{link}(\\{nest}[\|p].\\{head\_field}))$;\5
\X219:Show the auxiliary field, \|a\X;\6
\&{end};\2\6
\&{end};\par
\fi

\M219. \P$\X219:Show the auxiliary field, \|a\X\S$\6
\&{case} $\\{abs}(\|m)\mathbin{\&{div}}(\\{max\_command}+1)$ \1\&{of}\6
\40: \37\&{begin} \37$\\{print\_nl}(\.{"prevdepth\ "})$;\6
\&{if} $\|a\L\\{ignore\_depth}$ \1\&{then}\5
$\\{print}(\.{"ignored"})$\6
\4\&{else} $\\{print\_scaled}(\|a)$;\2\6
\&{if} $\\{nest}[\|p].\\{pg\_field}\I0$ \1\&{then}\6
\&{begin} \37$\\{print}(\.{",\ prevgraf\ "})$;\5
$\\{print\_int}(\\{nest}[\|p].\\{pg\_field})$;\5
$\\{print}(\.{"\ line"})$;\6
\&{if} $\\{nest}[\|p].\\{pg\_field}\I1$ \1\&{then}\5
$\\{print\_char}(\.{"s"})$;\2\6
\&{end};\2\6
\&{end};\6
\41: \37\&{begin} \37$\\{print\_nl}(\.{"spacefactor\ "})$;\5
$\\{print\_int}(\|a)$;\6
\&{end};\6
\42: \37\&{if} $\|a\I\\{null}$ \1\&{then}\6
\&{begin} \37$\\{print}(\.{"this\ will\ be\ denominator\ of:"})$;\5
$\\{show\_box}(\|a)$;\6
\&{end};\2\2\6
\&{end}\C{there are no other cases}\par
\U section~218.\fi

\N220.  \[17] The table of equivalents.
Now that we have studied the data structures for \TeX's semantic routines,
let us consider the data structures used by its syntactic routines. In
other words, we turn now to the tables that \TeX\ looks at when it is scanning
what the user has written.

The biggest and most important such table is called \\{eqtb}. It holds the
current ``equivalents'' of things; i.e., it explains what things mean
or what their current values are, for all quantities that are subject to
the nesting structure provided by \TeX's grouping mechanism. There are six
parts to \\{eqtb}:

\yskip\hang 1) $\\{eqtb}[\\{active\_base}\to(\\{hash\_base}-1)]$ holds the
current
equivalents of single-character control sequences.

\yskip\hang 2) $\\{eqtb}[\\{hash\_base}\to(\\{glue\_base}-1)]$ holds the
current
equivalents of multiletter control sequences.

\yskip\hang 3) $\\{eqtb}[\\{glue\_base}\to(\\{local\_base}-1)]$ holds the
current
equivalents of glue parameters like the current baselineskip.

\yskip\hang 4) $\\{eqtb}[\\{local\_base}\to(\\{int\_base}-1)]$ holds the
current
equivalents of local halfword quantities like the current box registers,
the current ``catcodes,'' the current font, and a pointer to the current
paragraph shape.

\yskip\hang 5) $\\{eqtb}[\\{int\_base}\to(\\{dimen\_base}-1)]$ holds the
current
equivalents of fullword integer parameters like the current hyphenation
penalty.

\yskip\hang 6) $\\{eqtb}[\\{dimen\_base}\to\\{eqtb\_size}]$ holds the current
equivalents
of fullword dimension parameters like the current hsize or amount of
hanging indentation.

\yskip\noindent Note that, for example, the current amount of
baselineskip glue is determined by the setting of a particular location
in region~3 of \\{eqtb}, while the current meaning of the control sequence
`\.{\\baselineskip}' (which might have been changed by \.{\\def} or
\.{\\let}) appears in region~2.

\fi

\M221. Each entry in \\{eqtb} is a \\{memory\_word}. Most of these words are of
type
\\{two\_halves}, and subdivided into three fields:

\yskip\hang 1) The \\{eq\_level} (a quarterword) is the level of grouping at
which this equivalent was defined. If the level is \\{level\_zero}, the
equivalent has never been defined; \\{level\_one} refers to the outer level
(outside of all groups), and this level is also used for global
definitions that never go away. Higher levels are for equivalents that
will disappear at the end of their group.

\yskip\hang 2) The \\{eq\_type} (another quarterword) specifies what kind of
entry this is. There are many types, since each \TeX\ primitive like
\.{\\hbox}, \.{\\def}, etc., has its own special code. The list of
command codes above includes all possible settings of the \\{eq\_type} field.

\yskip\hang 3) The \\{equiv} (a halfword) is the current equivalent value.
This may be a font number, a pointer into \\{mem}, or a variety of other
things.

\Y\P\D \37$\\{eq\_level\_field}(\#)\S\#.\\{hh}.\\{b1}$\par
\P\D \37$\\{eq\_type\_field}(\#)\S\#.\\{hh}.\\{b0}$\par
\P\D \37$\\{equiv\_field}(\#)\S\#.\\{hh}.\\{rh}$\par
\P\D \37$\\{eq\_level}(\#)\S\\{eq\_level\_field}(\\{eqtb}[\#])$\C{level of
definition}\par
\P\D \37$\\{eq\_type}(\#)\S\\{eq\_type\_field}(\\{eqtb}[\#])$\C{command code
for equivalent}\par
\P\D \37$\\{equiv}(\#)\S\\{equiv\_field}(\\{eqtb}[\#])$\C{equivalent value}\par
\P\D \37$\\{level\_zero}=\\{min\_quarterword}$\C{level for undefined
quantities}\par
\P\D \37$\\{level\_one}=\\{level\_zero}+1$\C{outermost level for defined
quantities}\par
\fi

\M222. Many locations in \\{eqtb} have symbolic names. The purpose of the next
paragraphs is to define these names, and to set up the initial values of the
equivalents.

In the first region we have 128 equivalents for ``active characters'' that
act as control sequences, followed by 128 equivalents for single-character
control sequences.

Then comes region~2, which corresponds to the hash table that we will
define later.  The maximum address in this region is used for a dummy
control sequence that is perpetually undefined. There also are several
locations for control sequences that are perpetually defined
(since they are used in error recovery).

\Y\P\D \37$\\{active\_base}=1$\C{beginning of region 1, for active character
equivalents}\par
\P\D \37$\\{single\_base}=\\{active\_base}+128$\C{equivalents of one-letter
control sequences}\par
\P\D \37$\\{null\_cs}=\\{single\_base}+128$\C{equivalent of \.{\\csname%
\\endcsname}}\par
\P\D \37$\\{hash\_base}=\\{null\_cs}+1$\C{beginning of region 2, for the hash
table}\par
\P\D \37$\\{frozen\_control\_sequence}=\\{hash\_base}+\\{hash\_size}$\C{for
error recovery}\par
\P\D \37$\\{frozen\_protection}=\\{frozen\_control\_sequence}$\C{inaccessible
but definable}\par
\P\D \37$\\{frozen\_cr}=\\{frozen\_control\_sequence}+1$\C{permanent `\.{%
\\cr}'}\par
\P\D \37$\\{frozen\_end\_group}=\\{frozen\_control\_sequence}+2$\C{permanent `%
\.{\\endgroup}'}\par
\P\D \37$\\{frozen\_right}=\\{frozen\_control\_sequence}+3$\C{permanent `\.{%
\\right}'}\par
\P\D \37$\\{frozen\_fi}=\\{frozen\_control\_sequence}+4$\C{permanent `\.{%
\\fi}'}\par
\P\D \37$\\{frozen\_end\_template}=\\{frozen\_control\_sequence}+5$\C{permanent
`\.{\\endtemplate}'}\par
\P\D \37$\\{frozen\_endv}=\\{frozen\_control\_sequence}+6$\C{second permanent `%
\.{\\endtemplate}'}\par
\P\D \37$\\{frozen\_relax}=\\{frozen\_control\_sequence}+7$\C{permanent `\.{%
\\relax}'}\par
\P\D \37$\\{end\_write}=\\{frozen\_control\_sequence}+8$\C{permanent `\.{%
\\endwrite}'}\par
\P\D \37$\\{frozen\_dont\_expand}=\\{frozen\_control\_sequence}+9$\C{permanent
`\.{\\notexpanded:}'}\par
\P\D \37$\\{frozen\_null\_font}=\\{frozen\_control\_sequence}+10$\C{permanent `%
\.{\\nullfont}'}\par
\P\D \37$\\{font\_id\_base}=\\{frozen\_null\_font}-\\{font\_base}$\C{begins
table of 257 permanent font identifiers}\par
\P\D \37$\\{undefined\_control\_sequence}=\\{frozen\_null\_font}+257$\C{dummy
location}\par
\P\D \37$\\{glue\_base}=\\{undefined\_control\_sequence}+1$\C{beginning of
region 3}\par
\Y\P$\4\X164:Initialize table entries (done by \.{INITEX} only)\X\mathrel{+}\S$%
\6
$\\{eq\_type}(\\{undefined\_control\_sequence})\K\\{undefined\_cs}$;\5
$\\{equiv}(\\{undefined\_control\_sequence})\K\\{null}$;\5
$\\{eq\_level}(\\{undefined\_control\_sequence})\K\\{level\_zero}$;\6
\&{for} $\|k\K\\{active\_base}\mathrel{\&{to}}\\{undefined\_control%
\_sequence}-1$ \1\&{do}\5
$\\{eqtb}[\|k]\K\\{eqtb}[\\{undefined\_control\_sequence}]$;\2\par
\fi

\M223. Here is a routine that displays the current meaning of an \\{eqtb} entry
in region 1 or~2. (Similar routines for the other regions will appear
below.)

\Y\P$\4\X223:Show equivalent \|n, in region 1 or 2\X\S$\6
\&{begin} \37$\\{sprint\_cs}(\|n)$;\5
$\\{print\_char}(\.{"="})$;\5
$\\{print\_cmd\_chr}(\\{eq\_type}(\|n),\39\\{equiv}(\|n))$;\6
\&{if} $\\{eq\_type}(\|n)\G\\{call}$ \1\&{then}\6
\&{begin} \37$\\{print\_char}(\.{":"})$;\5
$\\{show\_token\_list}(\\{link}(\\{equiv}(\|n)),\39\\{null},\3932)$;\6
\&{end};\2\6
\&{end}\par
\U section~252.\fi

\M224. Region 3 of \\{eqtb} contains the 256 \.{\\skip} registers, as well as
the
glue parameters defined here. It is important that the ``muskip''
parameters have larger numbers than the others.

\Y\P\D \37$\\{line\_skip\_code}=0$\C{interline glue if \\{baseline\_skip} is
infeasible}\par
\P\D \37$\\{baseline\_skip\_code}=1$\C{desired glue between baselines}\par
\P\D \37$\\{par\_skip\_code}=2$\C{extra glue just above a paragraph}\par
\P\D \37$\\{above\_display\_skip\_code}=3$\C{extra glue just above displayed
math}\par
\P\D \37$\\{below\_display\_skip\_code}=4$\C{extra glue just below displayed
math}\par
\P\D \37$\\{above\_display\_short\_skip\_code}=5$\C{glue above displayed math
following short lines}\par
\P\D \37$\\{below\_display\_short\_skip\_code}=6$\C{glue below displayed math
following short lines}\par
\P\D \37$\\{left\_skip\_code}=7$\C{glue at left of justified lines}\par
\P\D \37$\\{right\_skip\_code}=8$\C{glue at right of justified lines}\par
\P\D \37$\\{top\_skip\_code}=9$\C{glue at top of main pages}\par
\P\D \37$\\{split\_top\_skip\_code}=10$\C{glue at top of split pages}\par
\P\D \37$\\{tab\_skip\_code}=11$\C{glue between aligned entries}\par
\P\D \37$\\{space\_skip\_code}=12$\C{glue between words (if not \\{zero%
\_glue})}\par
\P\D \37$\\{xspace\_skip\_code}=13$\C{glue after sentences (if not \\{zero%
\_glue})}\par
\P\D \37$\\{par\_fill\_skip\_code}=14$\C{glue on last line of paragraph}\par
\P\D \37$\\{thin\_mu\_skip\_code}=15$\C{thin space in math formula}\par
\P\D \37$\\{med\_mu\_skip\_code}=16$\C{medium space in math formula}\par
\P\D \37$\\{thick\_mu\_skip\_code}=17$\C{thick space in math formula}\par
\P\D \37$\\{glue\_pars}=18$\C{total number of glue parameters}\par
\P\D \37$\\{skip\_base}=\\{glue\_base}+\\{glue\_pars}$\C{table of 256 ``skip''
registers}\par
\P\D \37$\\{mu\_skip\_base}=\\{skip\_base}+256$\C{table of 256 ``muskip''
registers}\par
\P\D \37$\\{local\_base}=\\{mu\_skip\_base}+256$\C{beginning of region 4}\Y\par
\P\D \37$\\{skip}(\#)\S\\{equiv}(\\{skip\_base}+\#)$\C{\\{mem} location of glue
specification}\par
\P\D \37$\\{mu\_skip}(\#)\S\\{equiv}(\\{mu\_skip\_base}+\#)$\C{\\{mem} location
of math glue spec}\par
\P\D \37$\\{glue\_par}(\#)\S\\{equiv}(\\{glue\_base}+\#)$\C{\\{mem} location of
glue specification}\par
\P\D \37$\\{line\_skip}\S\\{glue\_par}(\\{line\_skip\_code})$\par
\P\D \37$\\{baseline\_skip}\S\\{glue\_par}(\\{baseline\_skip\_code})$\par
\P\D \37$\\{par\_skip}\S\\{glue\_par}(\\{par\_skip\_code})$\par
\P\D \37$\\{above\_display\_skip}\S\\{glue\_par}(\\{above\_display\_skip%
\_code})$\par
\P\D \37$\\{below\_display\_skip}\S\\{glue\_par}(\\{below\_display\_skip%
\_code})$\par
\P\D \37$\\{above\_display\_short\_skip}\S\\{glue\_par}(\\{above\_display%
\_short\_skip\_code})$\par
\P\D \37$\\{below\_display\_short\_skip}\S\\{glue\_par}(\\{below\_display%
\_short\_skip\_code})$\par
\P\D \37$\\{left\_skip}\S\\{glue\_par}(\\{left\_skip\_code})$\par
\P\D \37$\\{right\_skip}\S\\{glue\_par}(\\{right\_skip\_code})$\par
\P\D \37$\\{top\_skip}\S\\{glue\_par}(\\{top\_skip\_code})$\par
\P\D \37$\\{split\_top\_skip}\S\\{glue\_par}(\\{split\_top\_skip\_code})$\par
\P\D \37$\\{tab\_skip}\S\\{glue\_par}(\\{tab\_skip\_code})$\par
\P\D \37$\\{space\_skip}\S\\{glue\_par}(\\{space\_skip\_code})$\par
\P\D \37$\\{xspace\_skip}\S\\{glue\_par}(\\{xspace\_skip\_code})$\par
\P\D \37$\\{par\_fill\_skip}\S\\{glue\_par}(\\{par\_fill\_skip\_code})$\par
\P\D \37$\\{thin\_mu\_skip}\S\\{glue\_par}(\\{thin\_mu\_skip\_code})$\par
\P\D \37$\\{med\_mu\_skip}\S\\{glue\_par}(\\{med\_mu\_skip\_code})$\par
\P\D \37$\\{thick\_mu\_skip}\S\\{glue\_par}(\\{thick\_mu\_skip\_code})$\par
\Y\P$\4\X224:Current \\{mem} equivalent of glue parameter number \|n\X\S$\6
$\\{glue\_par}(\|n)$\par
\U sections~152 and~154.\fi

\M225. Sometimes we need to convert \TeX's internal code numbers into symbolic
form. The \\{print\_skip\_param} routine gives the symbolic name of a glue
parameter.

\Y\P$\4\X225:Declare the procedure called \\{print\_skip\_param}\X\S$\6
\4\&{procedure}\1\  \37$\\{print\_skip\_param}(\|n:\\{integer})$;\2\6
\&{begin} \37\&{case} $\|n$ \1\&{of}\6
\4\\{line\_skip\_code}: \37$\\{print\_esc}(\.{"lineskip"})$;\6
\4\\{baseline\_skip\_code}: \37$\\{print\_esc}(\.{"baselineskip"})$;\6
\4\\{par\_skip\_code}: \37$\\{print\_esc}(\.{"parskip"})$;\6
\4\\{above\_display\_skip\_code}: \37$\\{print\_esc}(\.{"abovedisplayskip"})$;\6
\4\\{below\_display\_skip\_code}: \37$\\{print\_esc}(\.{"belowdisplayskip"})$;\6
\4\\{above\_display\_short\_skip\_code}: \37$\\{print\_esc}(%
\.{"abovedisplayshortskip"})$;\6
\4\\{below\_display\_short\_skip\_code}: \37$\\{print\_esc}(%
\.{"belowdisplayshortskip"})$;\6
\4\\{left\_skip\_code}: \37$\\{print\_esc}(\.{"leftskip"})$;\6
\4\\{right\_skip\_code}: \37$\\{print\_esc}(\.{"rightskip"})$;\6
\4\\{top\_skip\_code}: \37$\\{print\_esc}(\.{"topskip"})$;\6
\4\\{split\_top\_skip\_code}: \37$\\{print\_esc}(\.{"splittopskip"})$;\6
\4\\{tab\_skip\_code}: \37$\\{print\_esc}(\.{"tabskip"})$;\6
\4\\{space\_skip\_code}: \37$\\{print\_esc}(\.{"spaceskip"})$;\6
\4\\{xspace\_skip\_code}: \37$\\{print\_esc}(\.{"xspaceskip"})$;\6
\4\\{par\_fill\_skip\_code}: \37$\\{print\_esc}(\.{"parfillskip"})$;\6
\4\\{thin\_mu\_skip\_code}: \37$\\{print\_esc}(\.{"thinmuskip"})$;\6
\4\\{med\_mu\_skip\_code}: \37$\\{print\_esc}(\.{"medmuskip"})$;\6
\4\\{thick\_mu\_skip\_code}: \37$\\{print\_esc}(\.{"thickmuskip"})$;\6
\4\&{othercases} \37$\\{print}(\.{"[unknown\ glue\ parameter!]"})$\2\6
\&{endcases};\6
\&{end};\par
\U section~179.\fi

\M226. The symbolic names for glue parameters are put into \TeX's hash table
by using the routine called \\{primitive}, defined below. Let us enter them
now, so that we don't have to list all those parameter names anywhere else.

\Y\P$\4\X226:Put each of \TeX's primitives into the hash table\X\S$\6
$\\{primitive}(\.{"lineskip"},\39\\{assign\_glue},\39\\{glue\_base}+\\{line%
\_skip\_code})$;\6
$\\{primitive}(\.{"baselineskip"},\39\\{assign\_glue},\39\\{glue\_base}+%
\\{baseline\_skip\_code})$;\6
$\\{primitive}(\.{"parskip"},\39\\{assign\_glue},\39\\{glue\_base}+\\{par\_skip%
\_code})$;\6
$\\{primitive}(\.{"abovedisplayskip"},\39\\{assign\_glue},\39\\{glue\_base}+%
\\{above\_display\_skip\_code})$;\6
$\\{primitive}(\.{"belowdisplayskip"},\39\\{assign\_glue},\39\\{glue\_base}+%
\\{below\_display\_skip\_code})$;\6
$\\{primitive}(\.{"abovedisplayshortskip"},\39\\{assign\_glue},\39\\{glue%
\_base}+\\{above\_display\_short\_skip\_code})$;\6
$\\{primitive}(\.{"belowdisplayshortskip"},\39\\{assign\_glue},\39\\{glue%
\_base}+\\{below\_display\_short\_skip\_code})$;\6
$\\{primitive}(\.{"leftskip"},\39\\{assign\_glue},\39\\{glue\_base}+\\{left%
\_skip\_code})$;\6
$\\{primitive}(\.{"rightskip"},\39\\{assign\_glue},\39\\{glue\_base}+\\{right%
\_skip\_code})$;\6
$\\{primitive}(\.{"topskip"},\39\\{assign\_glue},\39\\{glue\_base}+\\{top\_skip%
\_code})$;\6
$\\{primitive}(\.{"splittopskip"},\39\\{assign\_glue},\39\\{glue\_base}+%
\\{split\_top\_skip\_code})$;\6
$\\{primitive}(\.{"tabskip"},\39\\{assign\_glue},\39\\{glue\_base}+\\{tab\_skip%
\_code})$;\6
$\\{primitive}(\.{"spaceskip"},\39\\{assign\_glue},\39\\{glue\_base}+\\{space%
\_skip\_code})$;\6
$\\{primitive}(\.{"xspaceskip"},\39\\{assign\_glue},\39\\{glue\_base}+\\{xspace%
\_skip\_code})$;\6
$\\{primitive}(\.{"parfillskip"},\39\\{assign\_glue},\39\\{glue\_base}+\\{par%
\_fill\_skip\_code})$;\6
$\\{primitive}(\.{"thinmuskip"},\39\\{assign\_mu\_glue},\39\\{glue\_base}+%
\\{thin\_mu\_skip\_code})$;\6
$\\{primitive}(\.{"medmuskip"},\39\\{assign\_mu\_glue},\39\\{glue\_base}+\\{med%
\_mu\_skip\_code})$;\6
$\\{primitive}(\.{"thickmuskip"},\39\\{assign\_mu\_glue},\39\\{glue\_base}+%
\\{thick\_mu\_skip\_code})$;\par
\A sections~230, 238, 248, 265\*, 334, 376, 384, 411, 416, 468, 487, 491, 553,
780, 983, 1052, 1058, 1071, 1088, 1107, 1114, 1141, 1156, 1169, 1178, 1188,
1208, 1219, 1222, 1230, 1250, 1254, 1262, 1272, 1277, 1286, 1291, and~1344.
\U section~1336.\fi

\M227. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\S$\6
\4$\\{assign\_glue},\39\\{assign\_mu\_glue}$: \37\&{if} $\\{chr\_code}<\\{skip%
\_base}$ \1\&{then}\5
$\\{print\_skip\_param}(\\{chr\_code}-\\{glue\_base})$\6
\4\&{else} \&{if} $\\{chr\_code}<\\{mu\_skip\_base}$ \1\&{then}\6
\&{begin} \37$\\{print\_esc}(\.{"skip"})$;\5
$\\{print\_int}(\\{chr\_code}-\\{skip\_base})$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{print\_esc}(\.{"muskip"})$;\5
$\\{print\_int}(\\{chr\_code}-\\{mu\_skip\_base})$;\6
\&{end};\2\2\par
\A sections~231, 239, 249, 266\*, 335, 377, 385, 412, 417, 469, 488, 492, 781,
984, 1053, 1059, 1072, 1089, 1108, 1115, 1143, 1157, 1170, 1179, 1189, 1209,
1220, 1223, 1231, 1251, 1255, 1261, 1263, 1273, 1278, 1287, 1292, 1295,
and~1346.
\U section~298.\fi

\M228. All glue parameters and registers are initially `\.{0pt plus0pt
minus0pt}'.

\Y\P$\4\X164:Initialize table entries (done by \.{INITEX} only)\X\mathrel{+}\S$%
\6
$\\{equiv}(\\{glue\_base})\K\\{zero\_glue}$;\5
$\\{eq\_level}(\\{glue\_base})\K\\{level\_one}$;\5
$\\{eq\_type}(\\{glue\_base})\K\\{glue\_ref}$;\6
\&{for} $\|k\K\\{glue\_base}+1\mathrel{\&{to}}\\{local\_base}-1$ \1\&{do}\5
$\\{eqtb}[\|k]\K\\{eqtb}[\\{glue\_base}]$;\2\6
$\\{glue\_ref\_count}(\\{zero\_glue})\K\\{glue\_ref\_count}(\\{zero\_glue})+%
\\{local\_base}-\\{glue\_base}$;\par
\fi

\M229. \P$\X229:Show equivalent \|n, in region 3\X\S$\6
\&{if} $\|n<\\{skip\_base}$ \1\&{then}\6
\&{begin} \37$\\{print\_skip\_param}(\|n-\\{glue\_base})$;\5
$\\{print\_char}(\.{"="})$;\6
\&{if} $\|n<\\{glue\_base}+\\{thin\_mu\_skip\_code}$ \1\&{then}\5
$\\{print\_spec}(\\{equiv}(\|n),\39\.{"pt"})$\6
\4\&{else} $\\{print\_spec}(\\{equiv}(\|n),\39\.{"mu"})$;\2\6
\&{end}\6
\4\&{else} \&{if} $\|n<\\{mu\_skip\_base}$ \1\&{then}\6
\&{begin} \37$\\{print\_esc}(\.{"skip"})$;\5
$\\{print\_int}(\|n-\\{skip\_base})$;\5
$\\{print\_char}(\.{"="})$;\5
$\\{print\_spec}(\\{equiv}(\|n),\39\.{"pt"})$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{print\_esc}(\.{"muskip"})$;\5
$\\{print\_int}(\|n-\\{mu\_skip\_base})$;\5
$\\{print\_char}(\.{"="})$;\5
$\\{print\_spec}(\\{equiv}(\|n),\39\.{"mu"})$;\6
\&{end}\2\2\par
\U section~252.\fi

\M230. Region 4 of \\{eqtb} contains the local quantities defined here. The
bulk of this region is taken up by five tables that are indexed by seven-bit
characters; these tables are important to both the syntactic and semantic
portions of \TeX. There are also a bunch of special things like font and
token parameters, as well as the tables of \.{\\toks} and \.{\\box}
registers.

\Y\P\D \37$\\{par\_shape\_loc}=\\{local\_base}$\C{specifies paragraph shape}\par
\P\D \37$\\{output\_routine\_loc}=\\{local\_base}+1$\C{points to token list for
\.{\\output}}\par
\P\D \37$\\{every\_par\_loc}=\\{local\_base}+2$\C{points to token list for \.{%
\\everypar}}\par
\P\D \37$\\{every\_math\_loc}=\\{local\_base}+3$\C{points to token list for \.{%
\\everymath}}\par
\P\D \37$\\{every\_display\_loc}=\\{local\_base}+4$\C{points to token list for %
\.{\\everydisplay}}\par
\P\D \37$\\{every\_hbox\_loc}=\\{local\_base}+5$\C{points to token list for \.{%
\\everyhbox}}\par
\P\D \37$\\{every\_vbox\_loc}=\\{local\_base}+6$\C{points to token list for \.{%
\\everyvbox}}\par
\P\D \37$\\{every\_job\_loc}=\\{local\_base}+7$\C{points to token list for \.{%
\\everyjob}}\par
\P\D \37$\\{every\_cr\_loc}=\\{local\_base}+8$\C{points to token list for \.{%
\\everycr}}\par
\P\D \37$\\{err\_help\_loc}=\\{local\_base}+9$\C{points to token list for \.{%
\\errhelp}}\par
\P\D \37$\\{toks\_base}=\\{local\_base}+10$\C{table of 256 token list
registers}\par
\P\D \37$\\{box\_base}=\\{toks\_base}+256$\C{table of 256 box registers}\par
\P\D \37$\\{cur\_font\_loc}=\\{box\_base}+256$\C{internal font number outside
math mode}\par
\P\D \37$\\{math\_font\_base}=\\{cur\_font\_loc}+1$\C{table of 48 math font
numbers}\par
\P\D \37$\\{cat\_code\_base}=\\{math\_font\_base}+48$\C{table of 128 command
codes (the ``catcodes'')}\par
\P\D \37$\\{lc\_code\_base}=\\{cat\_code\_base}+128$\C{table of 128 lowercase
mappings}\par
\P\D \37$\\{uc\_code\_base}=\\{lc\_code\_base}+128$\C{table of 128 uppercase
mappings}\par
\P\D \37$\\{sf\_code\_base}=\\{uc\_code\_base}+128$\C{table of 128 spacefactor
mappings}\par
\P\D \37$\\{math\_code\_base}=\\{sf\_code\_base}+128$\C{table of 128 math mode
mappings}\par
\P\D \37$\\{int\_base}=\\{math\_code\_base}+128$\C{beginning of region 5}\Y\par
\P\D \37$\\{par\_shape\_ptr}\S\\{equiv}(\\{par\_shape\_loc})$\par
\P\D \37$\\{output\_routine}\S\\{equiv}(\\{output\_routine\_loc})$\par
\P\D \37$\\{every\_par}\S\\{equiv}(\\{every\_par\_loc})$\par
\P\D \37$\\{every\_math}\S\\{equiv}(\\{every\_math\_loc})$\par
\P\D \37$\\{every\_display}\S\\{equiv}(\\{every\_display\_loc})$\par
\P\D \37$\\{every\_hbox}\S\\{equiv}(\\{every\_hbox\_loc})$\par
\P\D \37$\\{every\_vbox}\S\\{equiv}(\\{every\_vbox\_loc})$\par
\P\D \37$\\{every\_job}\S\\{equiv}(\\{every\_job\_loc})$\par
\P\D \37$\\{every\_cr}\S\\{equiv}(\\{every\_cr\_loc})$\par
\P\D \37$\\{err\_help}\S\\{equiv}(\\{err\_help\_loc})$\par
\P\D \37$\\{toks}(\#)\S\\{equiv}(\\{toks\_base}+\#)$\par
\P\D \37$\\{box}(\#)\S\\{equiv}(\\{box\_base}+\#)$\par
\P\D \37$\\{cur\_font}\S\\{equiv}(\\{cur\_font\_loc})$\par
\P\D \37$\\{fam\_fnt}(\#)\S\\{equiv}(\\{math\_font\_base}+\#)$\par
\P\D \37$\\{cat\_code}(\#)\S\\{equiv}(\\{cat\_code\_base}+\#)$\par
\P\D \37$\\{lc\_code}(\#)\S\\{equiv}(\\{lc\_code\_base}+\#)$\par
\P\D \37$\\{uc\_code}(\#)\S\\{equiv}(\\{uc\_code\_base}+\#)$\par
\P\D \37$\\{sf\_code}(\#)\S\\{equiv}(\\{sf\_code\_base}+\#)$\par
\P\D \37$\\{math\_code}(\#)\S\\{equiv}(\\{math\_code\_base}+\#)$\C{Note: $%
\\{math\_code}(\|c)$ is the true math code plus \\{min\_halfword}}\par
\Y\P$\4\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}\S$\6
$\\{primitive}(\.{"output"},\39\\{assign\_toks},\39\\{output\_routine\_loc})$;\5
$\\{primitive}(\.{"everypar"},\39\\{assign\_toks},\39\\{every\_par\_loc})$;\5
$\\{primitive}(\.{"everymath"},\39\\{assign\_toks},\39\\{every\_math\_loc})$;\5
$\\{primitive}(\.{"everydisplay"},\39\\{assign\_toks},\39\\{every\_display%
\_loc})$;\5
$\\{primitive}(\.{"everyhbox"},\39\\{assign\_toks},\39\\{every\_hbox\_loc})$;\5
$\\{primitive}(\.{"everyvbox"},\39\\{assign\_toks},\39\\{every\_vbox\_loc})$;\5
$\\{primitive}(\.{"everyjob"},\39\\{assign\_toks},\39\\{every\_job\_loc})$;\5
$\\{primitive}(\.{"everycr"},\39\\{assign\_toks},\39\\{every\_cr\_loc})$;\5
$\\{primitive}(\.{"errhelp"},\39\\{assign\_toks},\39\\{err\_help\_loc})$;\par
\fi

\M231. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{assign\_toks}: \37\&{if} $\\{chr\_code}\G\\{toks\_base}$ \1\&{then}\6
\&{begin} \37$\\{print\_esc}(\.{"toks"})$;\5
$\\{print\_int}(\\{chr\_code}-\\{toks\_base})$;\6
\&{end}\6
\4\&{else} \&{case} $\\{chr\_code}$ \1\&{of}\6
\4\\{output\_routine\_loc}: \37$\\{print\_esc}(\.{"output"})$;\6
\4\\{every\_par\_loc}: \37$\\{print\_esc}(\.{"everypar"})$;\6
\4\\{every\_math\_loc}: \37$\\{print\_esc}(\.{"everymath"})$;\6
\4\\{every\_display\_loc}: \37$\\{print\_esc}(\.{"everydisplay"})$;\6
\4\\{every\_hbox\_loc}: \37$\\{print\_esc}(\.{"everyhbox"})$;\6
\4\\{every\_vbox\_loc}: \37$\\{print\_esc}(\.{"everyvbox"})$;\6
\4\\{every\_job\_loc}: \37$\\{print\_esc}(\.{"everyjob"})$;\6
\4\\{every\_cr\_loc}: \37$\\{print\_esc}(\.{"everycr"})$;\6
\4\&{othercases} \37$\\{print\_esc}(\.{"errhelp"})$\2\6
\&{endcases};\2\par
\fi

\M232\*. We initialize most things to null or undefined values. An undefined
font
is represented by the internal code \\{font\_base}.

However, the character code tables are given initial values based on the
conventional interpretation of ASCII code. These initial values should
not be changed when \TeX\ is adapted for use with non-English languages;
all changes to the initialization conventions should be made in format
packages, not in \TeX\ itself, so that global interchange of formats is
possible.

\Y\P\D \37$\\{null\_font}\S\\{font\_base}$\par
\P\D \37$\\{var\_code}\S\O{70000}$\C{math code meaning ``use the current
family''}\par
\Y\P$\4\X164:Initialize table entries (done by \.{INITEX} only)\X\mathrel{+}\S$%
\6
$\\{par\_shape\_ptr}\K\\{null}$;\5
$\\{eq\_type}(\\{par\_shape\_loc})\K\\{shape\_ref}$;\5
$\\{eq\_level}(\\{par\_shape\_loc})\K\\{level\_one}$;\6
\&{for} $\|k\K\\{output\_routine\_loc}\mathrel{\&{to}}\\{toks\_base}+255$ \1%
\&{do}\5
$\\{eqtb}[\|k]\K\\{eqtb}[\\{undefined\_control\_sequence}]$;\2\6
$\\{box}(0)\K\\{null}$;\5
$\\{eq\_type}(\\{box\_base})\K\\{box\_ref}$;\5
$\\{eq\_level}(\\{box\_base})\K\\{level\_one}$;\6
\&{for} $\|k\K\\{box\_base}+1\mathrel{\&{to}}\\{box\_base}+255$ \1\&{do}\5
$\\{eqtb}[\|k]\K\\{eqtb}[\\{box\_base}]$;\2\6
$\\{cur\_font}\K\\{null\_font}$;\5
$\\{eq\_type}(\\{cur\_font\_loc})\K\\{data}$;\5
$\\{eq\_level}(\\{cur\_font\_loc})\K\\{level\_one}$;\6
\&{for} $\|k\K\\{math\_font\_base}\mathrel{\&{to}}\\{math\_font\_base}+47$ \1%
\&{do}\5
$\\{eqtb}[\|k]\K\\{eqtb}[\\{cur\_font\_loc}]$;\2\6
$\\{equiv}(\\{cat\_code\_base})\K0$;\5
$\\{eq\_type}(\\{cat\_code\_base})\K\\{data}$;\5
$\\{eq\_level}(\\{cat\_code\_base})\K\\{level\_one}$;\6
\&{for} $\|k\K\\{cat\_code\_base}+1\mathrel{\&{to}}\\{int\_base}-1$ \1\&{do}\5
$\\{eqtb}[\|k]\K\\{eqtb}[\\{cat\_code\_base}]$;\2\6
\&{for} $\|k\K0\mathrel{\&{to}}127$ \1\&{do}\6
\&{begin} \37$\\{cat\_code}(\|k)\K\\{other\_char}$;\5
$\\{math\_code}(\|k)\K\\{hi}(\|k)$;\5
$\\{sf\_code}(\|k)\K1000$;\6
\&{end};\2\6
$\\{cat\_code}(\\{carriage\_return})\K\\{car\_ret}$;\5
$\\{cat\_code}(\.{"\ "})\K\\{spacer}$;\5
$\\{cat\_code}(\.{"\\"})\K\\{escape}$;\5
$\\{cat\_code}(\.{"\%"})\K\\{comment}$;\5
$\\{cat\_code}(\\{form\_feed})\K\\{car\_ret}$;\5
$\\{cat\_code}(\\{invalid\_code})\K\\{invalid\_char}$;\5
$\\{cat\_code}(\\{null\_code})\K\\{ignore}$;\6
\&{for} $\|k\K\.{"0"}\mathrel{\&{to}}\.{"9"}$ \1\&{do}\5
$\\{math\_code}(\|k)\K\\{hi}(\|k+\\{var\_code})$;\2\6
\&{for} $\|k\K\.{"A"}\mathrel{\&{to}}\.{"Z"}$ \1\&{do}\6
\&{begin} \37$\\{cat\_code}(\|k)\K\\{letter}$;\5
$\\{cat\_code}(\|k+\.{"a"}-\.{"A"})\K\\{letter}$;\6
$\\{math\_code}(\|k)\K\\{hi}(\|k+\\{var\_code}+\H{100})$;\5
$\\{math\_code}(\|k+\.{"a"}-\.{"A"})\K\\{hi}(\|k+\.{"a"}-\.{"A"}+\\{var\_code}+%
\H{100})$;\6
$\\{lc\_code}(\|k)\K\|k+\.{"a"}-\.{"A"}$;\5
$\\{lc\_code}(\|k+\.{"a"}-\.{"A"})\K\|k+\.{"a"}-\.{"A"}$;\6
$\\{uc\_code}(\|k)\K\|k$;\5
$\\{uc\_code}(\|k+\.{"a"}-\.{"A"})\K\|k$;\6
$\\{sf\_code}(\|k)\K999$;\6
\&{end};\2\par
\fi

\M233. \P$\X233:Show equivalent \|n, in region 4\X\S$\6
\&{if} $\|n=\\{par\_shape\_loc}$ \1\&{then}\6
\&{begin} \37$\\{print\_esc}(\.{"parshape"})$;\5
$\\{print\_char}(\.{"="})$;\6
\&{if} $\\{par\_shape\_ptr}=\\{null}$ \1\&{then}\5
$\\{print\_char}(\.{"0"})$\6
\4\&{else} $\\{print\_int}(\\{info}(\\{par\_shape\_ptr}))$;\2\6
\&{end}\6
\4\&{else} \&{if} $\|n<\\{toks\_base}$ \1\&{then}\6
\&{begin} \37$\\{print\_cmd\_chr}(\\{assign\_toks},\39\|n)$;\5
$\\{print\_char}(\.{"="})$;\6
\&{if} $\\{equiv}(\|n)\I\\{null}$ \1\&{then}\5
$\\{show\_token\_list}(\\{link}(\\{equiv}(\|n)),\39\\{null},\3932)$;\2\6
\&{end}\6
\4\&{else} \&{if} $\|n<\\{box\_base}$ \1\&{then}\6
\&{begin} \37$\\{print\_esc}(\.{"toks"})$;\5
$\\{print\_int}(\|n-\\{toks\_base})$;\5
$\\{print\_char}(\.{"="})$;\6
\&{if} $\\{equiv}(\|n)\I\\{null}$ \1\&{then}\5
$\\{show\_token\_list}(\\{link}(\\{equiv}(\|n)),\39\\{null},\3932)$;\2\6
\&{end}\6
\4\&{else} \&{if} $\|n<\\{cur\_font\_loc}$ \1\&{then}\6
\&{begin} \37$\\{print\_esc}(\.{"box"})$;\5
$\\{print\_int}(\|n-\\{box\_base})$;\5
$\\{print\_char}(\.{"="})$;\6
\&{if} $\\{equiv}(\|n)=\\{null}$ \1\&{then}\5
$\\{print}(\.{"void"})$\6
\4\&{else} \&{begin} \37$\\{depth\_threshold}\K0$;\5
$\\{breadth\_max}\K1$;\5
$\\{show\_node\_list}(\\{equiv}(\|n))$;\6
\&{end};\2\6
\&{end}\6
\4\&{else} \&{if} $\|n<\\{cat\_code\_base}$ \1\&{then}\5
\X234:Show the font identifier in $\\{eqtb}[\|n]$\X\6
\4\&{else} \X235:Show the halfword code in $\\{eqtb}[\|n]$\X\2\2\2\2\2\par
\U section~252.\fi

\M234. \P$\X234:Show the font identifier in $\\{eqtb}[\|n]$\X\S$\6
\&{begin} \37\&{if} $\|n=\\{cur\_font\_loc}$ \1\&{then}\5
$\\{print}(\.{"current\ font"})$\6
\4\&{else} \&{if} $\|n<\\{math\_font\_base}+16$ \1\&{then}\6
\&{begin} \37$\\{print\_esc}(\.{"textfont"})$;\5
$\\{print\_int}(\|n-\\{math\_font\_base})$;\6
\&{end}\6
\4\&{else} \&{if} $\|n<\\{math\_font\_base}+32$ \1\&{then}\6
\&{begin} \37$\\{print\_esc}(\.{"scriptfont"})$;\5
$\\{print\_int}(\|n-\\{math\_font\_base}-16)$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{print\_esc}(\.{"scriptscriptfont"})$;\5
$\\{print\_int}(\|n-\\{math\_font\_base}-32)$;\6
\&{end};\2\2\2\6
$\\{print\_char}(\.{"="})$;\6
$\\{print\_esc}(\\{hash}[\\{font\_id\_base}+\\{equiv}(\|n)].\\{rh})$;\C{that's
$\\{text}(\\{font\_id\_base}+\\{equiv}(\|n))$}\6
\&{end}\par
\U section~233.\fi

\M235. \P$\X235:Show the halfword code in $\\{eqtb}[\|n]$\X\S$\6
\&{if} $\|n<\\{math\_code\_base}$ \1\&{then}\6
\&{begin} \37\&{if} $\|n<\\{lc\_code\_base}$ \1\&{then}\6
\&{begin} \37$\\{print\_esc}(\.{"catcode"})$;\5
$\\{print\_int}(\|n-\\{cat\_code\_base})$;\6
\&{end}\6
\4\&{else} \&{if} $\|n<\\{uc\_code\_base}$ \1\&{then}\6
\&{begin} \37$\\{print\_esc}(\.{"lccode"})$;\5
$\\{print\_int}(\|n-\\{lc\_code\_base})$;\6
\&{end}\6
\4\&{else} \&{if} $\|n<\\{sf\_code\_base}$ \1\&{then}\6
\&{begin} \37$\\{print\_esc}(\.{"uccode"})$;\5
$\\{print\_int}(\|n-\\{uc\_code\_base})$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{print\_esc}(\.{"sfcode"})$;\5
$\\{print\_int}(\|n-\\{sf\_code\_base})$;\6
\&{end};\2\2\2\6
$\\{print\_char}(\.{"="})$;\5
$\\{print\_int}(\\{equiv}(\|n))$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{print\_esc}(\.{"mathcode"})$;\5
$\\{print\_int}(\|n-\\{math\_code\_base})$;\5
$\\{print\_char}(\.{"="})$;\5
$\\{print\_int}(\\{ho}(\\{equiv}(\|n)))$;\6
\&{end}\2\par
\U section~233.\fi

\M236. Region 5 of \\{eqtb} contains the integer parameters and registers
defined
here, as well as the \\{del\_code} table. The latter table differs from the
$\\{cat\_code}\to\\{math\_code}$ tables that precede it, since delimiter codes
are
fullword integers while the other kinds of codes occupy at most a
halfword. This is what makes region~5 different from region~4. We will
store the \\{eq\_level} information in an auxiliary array of quarterwords
that will be defined later.

\Y\P\D \37$\\{pretolerance\_code}=0$\C{badness tolerance before hyphenation}\par
\P\D \37$\\{tolerance\_code}=1$\C{badness tolerance after hyphenation}\par
\P\D \37$\\{line\_penalty\_code}=2$\C{added to the badness of every line}\par
\P\D \37$\\{hyphen\_penalty\_code}=3$\C{penalty for break after discretionary
hyphen}\par
\P\D \37$\\{ex\_hyphen\_penalty\_code}=4$\C{penalty for break after explicit
hyphen}\par
\P\D \37$\\{club\_penalty\_code}=5$\C{penalty for creating a club line}\par
\P\D \37$\\{widow\_penalty\_code}=6$\C{penalty for creating a widow line}\par
\P\D \37$\\{display\_widow\_penalty\_code}=7$\C{ditto, just before a display}%
\par
\P\D \37$\\{broken\_penalty\_code}=8$\C{penalty for breaking a page at a broken
line}\par
\P\D \37$\\{bin\_op\_penalty\_code}=9$\C{penalty for breaking after a binary
operation}\par
\P\D \37$\\{rel\_penalty\_code}=10$\C{penalty for breaking after a relation}\par
\P\D \37$\\{pre\_display\_penalty\_code}=11$\C{penalty for breaking just before
a displayed formula}\par
\P\D \37$\\{post\_display\_penalty\_code}=12$\C{penalty for breaking just after
a displayed formula}\par
\P\D \37$\\{inter\_line\_penalty\_code}=13$\C{additional penalty between lines}%
\par
\P\D \37$\\{double\_hyphen\_demerits\_code}=14$\C{demerits for double hyphen
break}\par
\P\D \37$\\{final\_hyphen\_demerits\_code}=15$\C{demerits for final hyphen
break}\par
\P\D \37$\\{adj\_demerits\_code}=16$\C{demerits for adjacent incompatible
lines}\par
\P\D \37$\\{mag\_code}=17$\C{magnification ratio}\par
\P\D \37$\\{delimiter\_factor\_code}=18$\C{ratio for variable-size delimiters}%
\par
\P\D \37$\\{looseness\_code}=19$\C{change in number of lines for a paragraph}%
\par
\P\D \37$\\{time\_code}=20$\C{current time of day}\par
\P\D \37$\\{day\_code}=21$\C{current day of the month}\par
\P\D \37$\\{month\_code}=22$\C{current month of the year}\par
\P\D \37$\\{year\_code}=23$\C{current year of our Lord}\par
\P\D \37$\\{show\_box\_breadth\_code}=24$\C{nodes per level in \\{show\_box}}%
\par
\P\D \37$\\{show\_box\_depth\_code}=25$\C{maximum level in \\{show\_box}}\par
\P\D \37$\\{hbadness\_code}=26$\C{hboxes exceeding this badness will be shown
by \\{hpack}}\par
\P\D \37$\\{vbadness\_code}=27$\C{vboxes exceeding this badness will be shown
by \\{vpack}}\par
\P\D \37$\\{pausing\_code}=28$\C{pause after each line is read from a file}\par
\P\D \37$\\{tracing\_online\_code}=29$\C{show diagnostic output on terminal}\par
\P\D \37$\\{tracing\_macros\_code}=30$\C{show macros as they are being
expanded}\par
\P\D \37$\\{tracing\_stats\_code}=31$\C{show memory usage if \TeX\ knows it}\par
\P\D \37$\\{tracing\_paragraphs\_code}=32$\C{show line-break calculations}\par
\P\D \37$\\{tracing\_pages\_code}=33$\C{show page-break calculations}\par
\P\D \37$\\{tracing\_output\_code}=34$\C{show boxes when they are shipped out}%
\par
\P\D \37$\\{tracing\_lost\_chars\_code}=35$\C{show characters that aren't in
the font}\par
\P\D \37$\\{tracing\_commands\_code}=36$\C{show command codes at \\{big%
\_switch}}\par
\P\D \37$\\{tracing\_restores\_code}=37$\C{show equivalents when they are
restored}\par
\P\D \37$\\{uc\_hyph\_code}=38$\C{hyphenate words beginning with a capital
letter}\par
\P\D \37$\\{output\_penalty\_code}=39$\C{penalty found at current page break}%
\par
\P\D \37$\\{max\_dead\_cycles\_code}=40$\C{bound on consecutive dead cycles of
output}\par
\P\D \37$\\{hang\_after\_code}=41$\C{hanging indentation changes after this
many lines}\par
\P\D \37$\\{floating\_penalty\_code}=42$\C{penalty for insertions heldover
after a split}\par
\P\D \37$\\{global\_defs\_code}=43$\C{override \.{\\global} specifications}\par
\P\D \37$\\{cur\_fam\_code}=44$\C{current family}\par
\P\D \37$\\{escape\_char\_code}=45$\C{escape character for token output}\par
\P\D \37$\\{default\_hyphen\_char\_code}=46$\C{value of \.{\\hyphenchar} when a
font is loaded}\par
\P\D \37$\\{default\_skew\_char\_code}=47$\C{value of \.{\\skewchar} when a
font is loaded}\par
\P\D \37$\\{end\_line\_char\_code}=48$\C{character placed at the right end of
the buffer}\par
\P\D \37$\\{new\_line\_char\_code}=49$\C{character that prints as \\{print%
\_ln}}\par
\P\D \37$\\{int\_pars}=50$\C{total number of integer parameters}\par
\P\D \37$\\{count\_base}=\\{int\_base}+\\{int\_pars}$\C{256 user \.{\\count}
registers}\par
\P\D \37$\\{del\_code\_base}=\\{count\_base}+256$\C{128 delimiter code
mappings}\par
\P\D \37$\\{dimen\_base}=\\{del\_code\_base}+128$\C{beginning of region 6}\Y\par
\P\D \37$\\{del\_code}(\#)\S\\{eqtb}[\\{del\_code\_base}+\#].\\{int}$\par
\P\D \37$\\{count}(\#)\S\\{eqtb}[\\{count\_base}+\#].\\{int}$\par
\P\D \37$\\{int\_par}(\#)\S\\{eqtb}[\\{int\_base}+\#].\\{int}$\C{an integer
parameter}\par
\P\D \37$\\{pretolerance}\S\\{int\_par}(\\{pretolerance\_code})$\par
\P\D \37$\\{tolerance}\S\\{int\_par}(\\{tolerance\_code})$\par
\P\D \37$\\{line\_penalty}\S\\{int\_par}(\\{line\_penalty\_code})$\par
\P\D \37$\\{hyphen\_penalty}\S\\{int\_par}(\\{hyphen\_penalty\_code})$\par
\P\D \37$\\{ex\_hyphen\_penalty}\S\\{int\_par}(\\{ex\_hyphen\_penalty\_code})$%
\par
\P\D \37$\\{club\_penalty}\S\\{int\_par}(\\{club\_penalty\_code})$\par
\P\D \37$\\{widow\_penalty}\S\\{int\_par}(\\{widow\_penalty\_code})$\par
\P\D \37$\\{display\_widow\_penalty}\S\\{int\_par}(\\{display\_widow\_penalty%
\_code})$\par
\P\D \37$\\{broken\_penalty}\S\\{int\_par}(\\{broken\_penalty\_code})$\par
\P\D \37$\\{bin\_op\_penalty}\S\\{int\_par}(\\{bin\_op\_penalty\_code})$\par
\P\D \37$\\{rel\_penalty}\S\\{int\_par}(\\{rel\_penalty\_code})$\par
\P\D \37$\\{pre\_display\_penalty}\S\\{int\_par}(\\{pre\_display\_penalty%
\_code})$\par
\P\D \37$\\{post\_display\_penalty}\S\\{int\_par}(\\{post\_display\_penalty%
\_code})$\par
\P\D \37$\\{inter\_line\_penalty}\S\\{int\_par}(\\{inter\_line\_penalty%
\_code})$\par
\P\D \37$\\{double\_hyphen\_demerits}\S\\{int\_par}(\\{double\_hyphen\_demerits%
\_code})$\par
\P\D \37$\\{final\_hyphen\_demerits}\S\\{int\_par}(\\{final\_hyphen\_demerits%
\_code})$\par
\P\D \37$\\{adj\_demerits}\S\\{int\_par}(\\{adj\_demerits\_code})$\par
\P\D \37$\\{mag}\S\\{int\_par}(\\{mag\_code})$\par
\P\D \37$\\{delimiter\_factor}\S\\{int\_par}(\\{delimiter\_factor\_code})$\par
\P\D \37$\\{looseness}\S\\{int\_par}(\\{looseness\_code})$\par
\P\D \37$\\{time}\S\\{int\_par}(\\{time\_code})$\par
\P\D \37$\\{day}\S\\{int\_par}(\\{day\_code})$\par
\P\D \37$\\{month}\S\\{int\_par}(\\{month\_code})$\par
\P\D \37$\\{year}\S\\{int\_par}(\\{year\_code})$\par
\P\D \37$\\{show\_box\_breadth}\S\\{int\_par}(\\{show\_box\_breadth\_code})$\par
\P\D \37$\\{show\_box\_depth}\S\\{int\_par}(\\{show\_box\_depth\_code})$\par
\P\D \37$\\{hbadness}\S\\{int\_par}(\\{hbadness\_code})$\par
\P\D \37$\\{vbadness}\S\\{int\_par}(\\{vbadness\_code})$\par
\P\D \37$\\{pausing}\S\\{int\_par}(\\{pausing\_code})$\par
\P\D \37$\\{tracing\_online}\S\\{int\_par}(\\{tracing\_online\_code})$\par
\P\D \37$\\{tracing\_macros}\S\\{int\_par}(\\{tracing\_macros\_code})$\par
\P\D \37$\\{tracing\_stats}\S\\{int\_par}(\\{tracing\_stats\_code})$\par
\P\D \37$\\{tracing\_paragraphs}\S\\{int\_par}(\\{tracing\_paragraphs\_code})$%
\par
\P\D \37$\\{tracing\_pages}\S\\{int\_par}(\\{tracing\_pages\_code})$\par
\P\D \37$\\{tracing\_output}\S\\{int\_par}(\\{tracing\_output\_code})$\par
\P\D \37$\\{tracing\_lost\_chars}\S\\{int\_par}(\\{tracing\_lost\_chars%
\_code})$\par
\P\D \37$\\{tracing\_commands}\S\\{int\_par}(\\{tracing\_commands\_code})$\par
\P\D \37$\\{tracing\_restores}\S\\{int\_par}(\\{tracing\_restores\_code})$\par
\P\D \37$\\{uc\_hyph}\S\\{int\_par}(\\{uc\_hyph\_code})$\par
\P\D \37$\\{output\_penalty}\S\\{int\_par}(\\{output\_penalty\_code})$\par
\P\D \37$\\{max\_dead\_cycles}\S\\{int\_par}(\\{max\_dead\_cycles\_code})$\par
\P\D \37$\\{hang\_after}\S\\{int\_par}(\\{hang\_after\_code})$\par
\P\D \37$\\{floating\_penalty}\S\\{int\_par}(\\{floating\_penalty\_code})$\par
\P\D \37$\\{global\_defs}\S\\{int\_par}(\\{global\_defs\_code})$\par
\P\D \37$\\{cur\_fam}\S\\{int\_par}(\\{cur\_fam\_code})$\par
\P\D \37$\\{escape\_char}\S\\{int\_par}(\\{escape\_char\_code})$\par
\P\D \37$\\{default\_hyphen\_char}\S\\{int\_par}(\\{default\_hyphen\_char%
\_code})$\par
\P\D \37$\\{default\_skew\_char}\S\\{int\_par}(\\{default\_skew\_char\_code})$%
\par
\P\D \37$\\{end\_line\_char}\S\\{int\_par}(\\{end\_line\_char\_code})$\par
\P\D \37$\\{new\_line\_char}\S\\{int\_par}(\\{new\_line\_char\_code})$\par
\Y\P$\4\X236:Assign the values $\\{depth\_threshold}\K\\{show\_box\_depth}$ and
$\\{breadth\_max}\K\\{show\_box\_breadth}$\X\S$\6
$\\{depth\_threshold}\K\\{show\_box\_depth}$;\5
$\\{breadth\_max}\K\\{show\_box\_breadth}$\par
\U section~198.\fi

\M237. We can print the symbolic name of an integer parameter as follows.

\Y\P\4\&{procedure}\1\  \37$\\{print\_param}(\|n:\\{integer})$;\2\6
\&{begin} \37\&{case} $\|n$ \1\&{of}\6
\4\\{pretolerance\_code}: \37$\\{print\_esc}(\.{"pretolerance"})$;\6
\4\\{tolerance\_code}: \37$\\{print\_esc}(\.{"tolerance"})$;\6
\4\\{line\_penalty\_code}: \37$\\{print\_esc}(\.{"linepenalty"})$;\6
\4\\{hyphen\_penalty\_code}: \37$\\{print\_esc}(\.{"hyphenpenalty"})$;\6
\4\\{ex\_hyphen\_penalty\_code}: \37$\\{print\_esc}(\.{"exhyphenpenalty"})$;\6
\4\\{club\_penalty\_code}: \37$\\{print\_esc}(\.{"clubpenalty"})$;\6
\4\\{widow\_penalty\_code}: \37$\\{print\_esc}(\.{"widowpenalty"})$;\6
\4\\{display\_widow\_penalty\_code}: \37$\\{print\_esc}(%
\.{"displaywidowpenalty"})$;\6
\4\\{broken\_penalty\_code}: \37$\\{print\_esc}(\.{"brokenpenalty"})$;\6
\4\\{bin\_op\_penalty\_code}: \37$\\{print\_esc}(\.{"binoppenalty"})$;\6
\4\\{rel\_penalty\_code}: \37$\\{print\_esc}(\.{"relpenalty"})$;\6
\4\\{pre\_display\_penalty\_code}: \37$\\{print\_esc}(%
\.{"predisplaypenalty"})$;\6
\4\\{post\_display\_penalty\_code}: \37$\\{print\_esc}(%
\.{"postdisplaypenalty"})$;\6
\4\\{inter\_line\_penalty\_code}: \37$\\{print\_esc}(\.{"interlinepenalty"})$;\6
\4\\{double\_hyphen\_demerits\_code}: \37$\\{print\_esc}(%
\.{"doublehyphendemerits"})$;\6
\4\\{final\_hyphen\_demerits\_code}: \37$\\{print\_esc}(%
\.{"finalhyphendemerits"})$;\6
\4\\{adj\_demerits\_code}: \37$\\{print\_esc}(\.{"adjdemerits"})$;\6
\4\\{mag\_code}: \37$\\{print\_esc}(\.{"mag"})$;\6
\4\\{delimiter\_factor\_code}: \37$\\{print\_esc}(\.{"delimiterfactor"})$;\6
\4\\{looseness\_code}: \37$\\{print\_esc}(\.{"looseness"})$;\6
\4\\{time\_code}: \37$\\{print\_esc}(\.{"time"})$;\6
\4\\{day\_code}: \37$\\{print\_esc}(\.{"day"})$;\6
\4\\{month\_code}: \37$\\{print\_esc}(\.{"month"})$;\6
\4\\{year\_code}: \37$\\{print\_esc}(\.{"year"})$;\6
\4\\{show\_box\_breadth\_code}: \37$\\{print\_esc}(\.{"showboxbreadth"})$;\6
\4\\{show\_box\_depth\_code}: \37$\\{print\_esc}(\.{"showboxdepth"})$;\6
\4\\{hbadness\_code}: \37$\\{print\_esc}(\.{"hbadness"})$;\6
\4\\{vbadness\_code}: \37$\\{print\_esc}(\.{"vbadness"})$;\6
\4\\{pausing\_code}: \37$\\{print\_esc}(\.{"pausing"})$;\6
\4\\{tracing\_online\_code}: \37$\\{print\_esc}(\.{"tracingonline"})$;\6
\4\\{tracing\_macros\_code}: \37$\\{print\_esc}(\.{"tracingmacros"})$;\6
\4\\{tracing\_stats\_code}: \37$\\{print\_esc}(\.{"tracingstats"})$;\6
\4\\{tracing\_paragraphs\_code}: \37$\\{print\_esc}(\.{"tracingparagraphs"})$;\6
\4\\{tracing\_pages\_code}: \37$\\{print\_esc}(\.{"tracingpages"})$;\6
\4\\{tracing\_output\_code}: \37$\\{print\_esc}(\.{"tracingoutput"})$;\6
\4\\{tracing\_lost\_chars\_code}: \37$\\{print\_esc}(\.{"tracinglostchars"})$;\6
\4\\{tracing\_commands\_code}: \37$\\{print\_esc}(\.{"tracingcommands"})$;\6
\4\\{tracing\_restores\_code}: \37$\\{print\_esc}(\.{"tracingrestores"})$;\6
\4\\{uc\_hyph\_code}: \37$\\{print\_esc}(\.{"uchyph"})$;\6
\4\\{output\_penalty\_code}: \37$\\{print\_esc}(\.{"outputpenalty"})$;\6
\4\\{max\_dead\_cycles\_code}: \37$\\{print\_esc}(\.{"maxdeadcycles"})$;\6
\4\\{hang\_after\_code}: \37$\\{print\_esc}(\.{"hangafter"})$;\6
\4\\{floating\_penalty\_code}: \37$\\{print\_esc}(\.{"floatingpenalty"})$;\6
\4\\{global\_defs\_code}: \37$\\{print\_esc}(\.{"globaldefs"})$;\6
\4\\{cur\_fam\_code}: \37$\\{print\_esc}(\.{"fam"})$;\6
\4\\{escape\_char\_code}: \37$\\{print\_esc}(\.{"escapechar"})$;\6
\4\\{default\_hyphen\_char\_code}: \37$\\{print\_esc}(%
\.{"defaulthyphenchar"})$;\6
\4\\{default\_skew\_char\_code}: \37$\\{print\_esc}(\.{"defaultskewchar"})$;\6
\4\\{end\_line\_char\_code}: \37$\\{print\_esc}(\.{"endlinechar"})$;\6
\4\\{new\_line\_char\_code}: \37$\\{print\_esc}(\.{"newlinechar"})$;\6
\4\&{othercases} \37$\\{print}(\.{"[unknown\ integer\ parameter!]"})$\2\6
\&{endcases};\6
\&{end};\par
\fi

\M238. The integer parameter names must be entered into the hash table.

\Y\P$\4\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}\S$\6
$\\{primitive}(\.{"pretolerance"},\39\\{assign\_int},\39\\{int\_base}+%
\\{pretolerance\_code})$;\6
$\\{primitive}(\.{"tolerance"},\39\\{assign\_int},\39\\{int\_base}+\\{tolerance%
\_code})$;\6
$\\{primitive}(\.{"linepenalty"},\39\\{assign\_int},\39\\{int\_base}+\\{line%
\_penalty\_code})$;\6
$\\{primitive}(\.{"hyphenpenalty"},\39\\{assign\_int},\39\\{int\_base}+%
\\{hyphen\_penalty\_code})$;\6
$\\{primitive}(\.{"exhyphenpenalty"},\39\\{assign\_int},\39\\{int\_base}+\\{ex%
\_hyphen\_penalty\_code})$;\6
$\\{primitive}(\.{"clubpenalty"},\39\\{assign\_int},\39\\{int\_base}+\\{club%
\_penalty\_code})$;\6
$\\{primitive}(\.{"widowpenalty"},\39\\{assign\_int},\39\\{int\_base}+\\{widow%
\_penalty\_code})$;\6
$\\{primitive}(\.{"displaywidowpenalty"},\39\\{assign\_int},\39\\{int\_base}+%
\\{display\_widow\_penalty\_code})$;\6
$\\{primitive}(\.{"brokenpenalty"},\39\\{assign\_int},\39\\{int\_base}+%
\\{broken\_penalty\_code})$;\6
$\\{primitive}(\.{"binoppenalty"},\39\\{assign\_int},\39\\{int\_base}+\\{bin%
\_op\_penalty\_code})$;\6
$\\{primitive}(\.{"relpenalty"},\39\\{assign\_int},\39\\{int\_base}+\\{rel%
\_penalty\_code})$;\6
$\\{primitive}(\.{"predisplaypenalty"},\39\\{assign\_int},\39\\{int\_base}+%
\\{pre\_display\_penalty\_code})$;\6
$\\{primitive}(\.{"postdisplaypenalty"},\39\\{assign\_int},\39\\{int\_base}+%
\\{post\_display\_penalty\_code})$;\6
$\\{primitive}(\.{"interlinepenalty"},\39\\{assign\_int},\39\\{int\_base}+%
\\{inter\_line\_penalty\_code})$;\6
$\\{primitive}(\.{"doublehyphendemerits"},\39\\{assign\_int},\39\\{int\_base}+%
\\{double\_hyphen\_demerits\_code})$;\6
$\\{primitive}(\.{"finalhyphendemerits"},\39\\{assign\_int},\39\\{int\_base}+%
\\{final\_hyphen\_demerits\_code})$;\6
$\\{primitive}(\.{"adjdemerits"},\39\\{assign\_int},\39\\{int\_base}+\\{adj%
\_demerits\_code})$;\6
$\\{primitive}(\.{"mag"},\39\\{assign\_int},\39\\{int\_base}+\\{mag\_code})$;\6
$\\{primitive}(\.{"delimiterfactor"},\39\\{assign\_int},\39\\{int\_base}+%
\\{delimiter\_factor\_code})$;\6
$\\{primitive}(\.{"looseness"},\39\\{assign\_int},\39\\{int\_base}+\\{looseness%
\_code})$;\6
$\\{primitive}(\.{"time"},\39\\{assign\_int},\39\\{int\_base}+\\{time\_code})$;%
\6
$\\{primitive}(\.{"day"},\39\\{assign\_int},\39\\{int\_base}+\\{day\_code})$;\6
$\\{primitive}(\.{"month"},\39\\{assign\_int},\39\\{int\_base}+\\{month%
\_code})$;\6
$\\{primitive}(\.{"year"},\39\\{assign\_int},\39\\{int\_base}+\\{year\_code})$;%
\6
$\\{primitive}(\.{"showboxbreadth"},\39\\{assign\_int},\39\\{int\_base}+\\{show%
\_box\_breadth\_code})$;\6
$\\{primitive}(\.{"showboxdepth"},\39\\{assign\_int},\39\\{int\_base}+\\{show%
\_box\_depth\_code})$;\6
$\\{primitive}(\.{"hbadness"},\39\\{assign\_int},\39\\{int\_base}+\\{hbadness%
\_code})$;\6
$\\{primitive}(\.{"vbadness"},\39\\{assign\_int},\39\\{int\_base}+\\{vbadness%
\_code})$;\6
$\\{primitive}(\.{"pausing"},\39\\{assign\_int},\39\\{int\_base}+\\{pausing%
\_code})$;\6
$\\{primitive}(\.{"tracingonline"},\39\\{assign\_int},\39\\{int\_base}+%
\\{tracing\_online\_code})$;\6
$\\{primitive}(\.{"tracingmacros"},\39\\{assign\_int},\39\\{int\_base}+%
\\{tracing\_macros\_code})$;\6
$\\{primitive}(\.{"tracingstats"},\39\\{assign\_int},\39\\{int\_base}+%
\\{tracing\_stats\_code})$;\6
$\\{primitive}(\.{"tracingparagraphs"},\39\\{assign\_int},\39\\{int\_base}+%
\\{tracing\_paragraphs\_code})$;\6
$\\{primitive}(\.{"tracingpages"},\39\\{assign\_int},\39\\{int\_base}+%
\\{tracing\_pages\_code})$;\6
$\\{primitive}(\.{"tracingoutput"},\39\\{assign\_int},\39\\{int\_base}+%
\\{tracing\_output\_code})$;\6
$\\{primitive}(\.{"tracinglostchars"},\39\\{assign\_int},\39\\{int\_base}+%
\\{tracing\_lost\_chars\_code})$;\6
$\\{primitive}(\.{"tracingcommands"},\39\\{assign\_int},\39\\{int\_base}+%
\\{tracing\_commands\_code})$;\6
$\\{primitive}(\.{"tracingrestores"},\39\\{assign\_int},\39\\{int\_base}+%
\\{tracing\_restores\_code})$;\6
$\\{primitive}(\.{"uchyph"},\39\\{assign\_int},\39\\{int\_base}+\\{uc\_hyph%
\_code})$;\6
$\\{primitive}(\.{"outputpenalty"},\39\\{assign\_int},\39\\{int\_base}+%
\\{output\_penalty\_code})$;\6
$\\{primitive}(\.{"maxdeadcycles"},\39\\{assign\_int},\39\\{int\_base}+\\{max%
\_dead\_cycles\_code})$;\6
$\\{primitive}(\.{"hangafter"},\39\\{assign\_int},\39\\{int\_base}+\\{hang%
\_after\_code})$;\6
$\\{primitive}(\.{"floatingpenalty"},\39\\{assign\_int},\39\\{int\_base}+%
\\{floating\_penalty\_code})$;\6
$\\{primitive}(\.{"globaldefs"},\39\\{assign\_int},\39\\{int\_base}+\\{global%
\_defs\_code})$;\6
$\\{primitive}(\.{"fam"},\39\\{assign\_int},\39\\{int\_base}+\\{cur\_fam%
\_code})$;\6
$\\{primitive}(\.{"escapechar"},\39\\{assign\_int},\39\\{int\_base}+\\{escape%
\_char\_code})$;\6
$\\{primitive}(\.{"defaulthyphenchar"},\39\\{assign\_int},\39\\{int\_base}+%
\\{default\_hyphen\_char\_code})$;\6
$\\{primitive}(\.{"defaultskewchar"},\39\\{assign\_int},\39\\{int\_base}+%
\\{default\_skew\_char\_code})$;\6
$\\{primitive}(\.{"endlinechar"},\39\\{assign\_int},\39\\{int\_base}+\\{end%
\_line\_char\_code})$;\6
$\\{primitive}(\.{"newlinechar"},\39\\{assign\_int},\39\\{int\_base}+\\{new%
\_line\_char\_code})$;\par
\fi

\M239. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{assign\_int}: \37\&{if} $\\{chr\_code}<\\{count\_base}$ \1\&{then}\5
$\\{print\_param}(\\{chr\_code}-\\{int\_base})$\6
\4\&{else} \&{begin} \37$\\{print\_esc}(\.{"count"})$;\5
$\\{print\_int}(\\{chr\_code}-\\{count\_base})$;\6
\&{end};\2\par
\fi

\M240. The integer parameters should really be initialized by a macro package;
the following initialization does the minimum to keep \TeX\ from
complete failure.

\Y\P$\4\X164:Initialize table entries (done by \.{INITEX} only)\X\mathrel{+}\S$%
\6
\&{for} $\|k\K\\{int\_base}\mathrel{\&{to}}\\{del\_code\_base}-1$ \1\&{do}\5
$\\{eqtb}[\|k].\\{int}\K0$;\2\6
$\\{mag}\K1000$;\5
$\\{tolerance}\K10000$;\5
$\\{hang\_after}\K1$;\5
$\\{max\_dead\_cycles}\K25$;\5
$\\{escape\_char}\K\.{"\\"}$;\5
$\\{end\_line\_char}\K\\{carriage\_return}$;\6
\&{for} $\|k\K0\mathrel{\&{to}}127$ \1\&{do}\5
$\\{del\_code}(\|k)\K-1$;\2\6
$\\{del\_code}(\.{"."})\K0$;\C{this null delimiter is used in error recovery}%
\par
\fi

\M241\*. The following procedure, which is called just before \TeX\ initializes
its
input and output, establishes the initial values of the date and time.
It uses a {\mc WAITS} monitor call that puts the date in the left 18 bits
and the time in the right 18 bits.

\Y\P\4\&{procedure}\1\  \37\\{fix\_date\_and\_time};\6
\4\&{var} \37\|t: \37\\{integer};\C{accumulator}\6
\\{date}: \37\\{integer};\C{raw date}\6
\|g: \37\\{boolean};\C{garbage}\2\6
\&{begin} \37$\\{call\_i}(\O{400101},\39,\39\|t,\39\|t,\39\|g)$;\C{that's %
\.{ACCTIM}}\6
$\\{date}\K\|t\mathbin{\&{div}}\O{1000000}$;\5
$\\{time}\K(\|t\mathbin{\&{mod}}\O{1000000})\mathbin{\&{div}}60$;\5
$\\{day}\K(\\{date}\mathbin{\&{mod}}31)+1$;\5
$\\{month}\K((\\{date}\mathbin{\&{div}}31)\mathbin{\&{mod}}12)+1$;\5
$\\{year}\K(\\{date}\mathbin{\&{div}}(31\ast12))+1964$;\6
\&{end};\par
\fi

\M242. \P$\X242:Show equivalent \|n, in region 5\X\S$\6
\&{begin} \37\&{if} $\|n<\\{count\_base}$ \1\&{then}\5
$\\{print\_param}(\|n-\\{int\_base})$\6
\4\&{else} \&{if} $\|n<\\{del\_code\_base}$ \1\&{then}\6
\&{begin} \37$\\{print\_esc}(\.{"count"})$;\5
$\\{print\_int}(\|n-\\{count\_base})$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{print\_esc}(\.{"delcode"})$;\5
$\\{print\_int}(\|n-\\{del\_code\_base})$;\6
\&{end};\2\2\6
$\\{print\_char}(\.{"="})$;\5
$\\{print\_int}(\\{eqtb}[\|n].\\{int})$;\6
\&{end}\par
\U section~252.\fi

\M243. \P$\X243:Set variable \|c to the current escape character\X\S$\6
$\|c\K\\{escape\_char}$\par
\U section~63.\fi

\M244. \P$\X244:Character \|s is the current new-line character\X\S$\6
$\|s=\\{new\_line\_char}$\par
\U sections~58, 59, and~60.\fi

\M245. \TeX\ is occasionally supposed to print diagnostic information that
goes only into the transcript file, unless \\{tracing\_online} is positive.
Here are two routines that adjust the destination of print commands:

\Y\P\4\&{procedure}\1\  \37\\{begin\_diagnostic};\C{prepare to do some tracing}%
\2\6
\&{begin} \37$\\{old\_setting}\K\\{selector}$;\6
\&{if} $(\\{tracing\_online}\L0)\W(\\{selector}=\\{term\_and\_log})$ \1\&{then}%
\6
\&{begin} \37$\\{decr}(\\{selector})$;\6
\&{if} $\\{history}=\\{spotless}$ \1\&{then}\5
$\\{history}\K\\{warning\_issued}$;\2\6
\&{end};\2\6
\&{end};\7
\4\&{procedure}\1\  \37$\\{end\_diagnostic}(\\{blank\_line}:\\{boolean})$;%
\C{restore proper conditions after tracing}\2\6
\&{begin} \37$\\{print\_nl}(\.{""})$;\6
\&{if} $\\{blank\_line}$ \1\&{then}\5
\\{print\_ln};\2\6
$\\{selector}\K\\{old\_setting}$;\6
\&{end};\par
\fi

\M246. Of course we had better declare another global variable, if the previous
routines are going to work.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{old\_setting}: \37$0\to\\{max\_selector}$;\par
\fi

\M247. The final region of \\{eqtb} contains the dimension parameters defined
here, and the 256 \.{\\dimen} registers.

\Y\P\D \37$\\{par\_indent\_code}=0$\C{indentation of paragraphs}\par
\P\D \37$\\{math\_surround\_code}=1$\C{space around math in text}\par
\P\D \37$\\{line\_skip\_limit\_code}=2$\C{threshold for \\{line\_skip} instead
of \\{baseline\_skip}}\par
\P\D \37$\\{hsize\_code}=3$\C{line width in horizontal mode}\par
\P\D \37$\\{vsize\_code}=4$\C{page height in vertical mode}\par
\P\D \37$\\{max\_depth\_code}=5$\C{maximum depth of boxes on main pages}\par
\P\D \37$\\{split\_max\_depth\_code}=6$\C{maximum depth of boxes on split
pages}\par
\P\D \37$\\{box\_max\_depth\_code}=7$\C{maximum depth of explicit vboxes}\par
\P\D \37$\\{hfuzz\_code}=8$\C{tolerance for overfull hbox messages}\par
\P\D \37$\\{vfuzz\_code}=9$\C{tolerance for overfull vbox messages}\par
\P\D \37$\\{delimiter\_shortfall\_code}=10$\C{maximum amount uncovered by
variable delimiters}\par
\P\D \37$\\{null\_delimiter\_space\_code}=11$\C{blank space in null delimiters}%
\par
\P\D \37$\\{script\_space\_code}=12$\C{extra space after subscript or
superscript}\par
\P\D \37$\\{pre\_display\_size\_code}=13$\C{length of text preceding a display}%
\par
\P\D \37$\\{display\_width\_code}=14$\C{length of line for displayed equation}%
\par
\P\D \37$\\{display\_indent\_code}=15$\C{indentation of line for displayed
equation}\par
\P\D \37$\\{overfull\_rule\_code}=16$\C{width of rule that identifies overfull
hboxes}\par
\P\D \37$\\{hang\_indent\_code}=17$\C{amount of hanging indentation}\par
\P\D \37$\\{h\_offset\_code}=18$\C{amount of horizontal offset when shipping
pages out}\par
\P\D \37$\\{v\_offset\_code}=19$\C{amount of vertical offset when shipping
pages out}\par
\P\D \37$\\{dimen\_pars}=20$\C{total number of dimension parameters}\par
\P\D \37$\\{scaled\_base}=\\{dimen\_base}+\\{dimen\_pars}$\C{table of 256
user-defined \.{\\dimen} registers}\par
\P\D \37$\\{eqtb\_size}=\\{scaled\_base}+255$\C{largest subscript of \\{eqtb}}%
\Y\par
\P\D \37$\\{dimen}(\#)\S\\{eqtb}[\\{scaled\_base}+\#].\\{sc}$\par
\P\D \37$\\{dimen\_par}(\#)\S\\{eqtb}[\\{dimen\_base}+\#].\\{sc}$\C{a scaled
quantity}\par
\P\D \37$\\{par\_indent}\S\\{dimen\_par}(\\{par\_indent\_code})$\par
\P\D \37$\\{math\_surround}\S\\{dimen\_par}(\\{math\_surround\_code})$\par
\P\D \37$\\{line\_skip\_limit}\S\\{dimen\_par}(\\{line\_skip\_limit\_code})$\par
\P\D \37$\\{hsize}\S\\{dimen\_par}(\\{hsize\_code})$\par
\P\D \37$\\{vsize}\S\\{dimen\_par}(\\{vsize\_code})$\par
\P\D \37$\\{max\_depth}\S\\{dimen\_par}(\\{max\_depth\_code})$\par
\P\D \37$\\{split\_max\_depth}\S\\{dimen\_par}(\\{split\_max\_depth\_code})$\par
\P\D \37$\\{box\_max\_depth}\S\\{dimen\_par}(\\{box\_max\_depth\_code})$\par
\P\D \37$\\{hfuzz}\S\\{dimen\_par}(\\{hfuzz\_code})$\par
\P\D \37$\\{vfuzz}\S\\{dimen\_par}(\\{vfuzz\_code})$\par
\P\D \37$\\{delimiter\_shortfall}\S\\{dimen\_par}(\\{delimiter\_shortfall%
\_code})$\par
\P\D \37$\\{null\_delimiter\_space}\S\\{dimen\_par}(\\{null\_delimiter\_space%
\_code})$\par
\P\D \37$\\{script\_space}\S\\{dimen\_par}(\\{script\_space\_code})$\par
\P\D \37$\\{pre\_display\_size}\S\\{dimen\_par}(\\{pre\_display\_size\_code})$%
\par
\P\D \37$\\{display\_width}\S\\{dimen\_par}(\\{display\_width\_code})$\par
\P\D \37$\\{display\_indent}\S\\{dimen\_par}(\\{display\_indent\_code})$\par
\P\D \37$\\{overfull\_rule}\S\\{dimen\_par}(\\{overfull\_rule\_code})$\par
\P\D \37$\\{hang\_indent}\S\\{dimen\_par}(\\{hang\_indent\_code})$\par
\P\D \37$\\{h\_offset}\S\\{dimen\_par}(\\{h\_offset\_code})$\par
\P\D \37$\\{v\_offset}\S\\{dimen\_par}(\\{v\_offset\_code})$\par
\Y\P\4\&{procedure}\1\  \37$\\{print\_length\_param}(\|n:\\{integer})$;\2\6
\&{begin} \37\&{case} $\|n$ \1\&{of}\6
\4\\{par\_indent\_code}: \37$\\{print\_esc}(\.{"parindent"})$;\6
\4\\{math\_surround\_code}: \37$\\{print\_esc}(\.{"mathsurround"})$;\6
\4\\{line\_skip\_limit\_code}: \37$\\{print\_esc}(\.{"lineskiplimit"})$;\6
\4\\{hsize\_code}: \37$\\{print\_esc}(\.{"hsize"})$;\6
\4\\{vsize\_code}: \37$\\{print\_esc}(\.{"vsize"})$;\6
\4\\{max\_depth\_code}: \37$\\{print\_esc}(\.{"maxdepth"})$;\6
\4\\{split\_max\_depth\_code}: \37$\\{print\_esc}(\.{"splitmaxdepth"})$;\6
\4\\{box\_max\_depth\_code}: \37$\\{print\_esc}(\.{"boxmaxdepth"})$;\6
\4\\{hfuzz\_code}: \37$\\{print\_esc}(\.{"hfuzz"})$;\6
\4\\{vfuzz\_code}: \37$\\{print\_esc}(\.{"vfuzz"})$;\6
\4\\{delimiter\_shortfall\_code}: \37$\\{print\_esc}(%
\.{"delimitershortfall"})$;\6
\4\\{null\_delimiter\_space\_code}: \37$\\{print\_esc}(%
\.{"nulldelimiterspace"})$;\6
\4\\{script\_space\_code}: \37$\\{print\_esc}(\.{"scriptspace"})$;\6
\4\\{pre\_display\_size\_code}: \37$\\{print\_esc}(\.{"predisplaysize"})$;\6
\4\\{display\_width\_code}: \37$\\{print\_esc}(\.{"displaywidth"})$;\6
\4\\{display\_indent\_code}: \37$\\{print\_esc}(\.{"displayindent"})$;\6
\4\\{overfull\_rule\_code}: \37$\\{print\_esc}(\.{"overfullrule"})$;\6
\4\\{hang\_indent\_code}: \37$\\{print\_esc}(\.{"hangindent"})$;\6
\4\\{h\_offset\_code}: \37$\\{print\_esc}(\.{"hoffset"})$;\6
\4\\{v\_offset\_code}: \37$\\{print\_esc}(\.{"voffset"})$;\6
\4\&{othercases} \37$\\{print}(\.{"[unknown\ dimen\ parameter!]"})$\2\6
\&{endcases};\6
\&{end};\par
\fi

\M248. \P$\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}%
\S$\6
$\\{primitive}(\.{"parindent"},\39\\{assign\_dimen},\39\\{dimen\_base}+\\{par%
\_indent\_code})$;\6
$\\{primitive}(\.{"mathsurround"},\39\\{assign\_dimen},\39\\{dimen\_base}+%
\\{math\_surround\_code})$;\6
$\\{primitive}(\.{"lineskiplimit"},\39\\{assign\_dimen},\39\\{dimen\_base}+%
\\{line\_skip\_limit\_code})$;\6
$\\{primitive}(\.{"hsize"},\39\\{assign\_dimen},\39\\{dimen\_base}+\\{hsize%
\_code})$;\6
$\\{primitive}(\.{"vsize"},\39\\{assign\_dimen},\39\\{dimen\_base}+\\{vsize%
\_code})$;\6
$\\{primitive}(\.{"maxdepth"},\39\\{assign\_dimen},\39\\{dimen\_base}+\\{max%
\_depth\_code})$;\6
$\\{primitive}(\.{"splitmaxdepth"},\39\\{assign\_dimen},\39\\{dimen\_base}+%
\\{split\_max\_depth\_code})$;\6
$\\{primitive}(\.{"boxmaxdepth"},\39\\{assign\_dimen},\39\\{dimen\_base}+\\{box%
\_max\_depth\_code})$;\6
$\\{primitive}(\.{"hfuzz"},\39\\{assign\_dimen},\39\\{dimen\_base}+\\{hfuzz%
\_code})$;\6
$\\{primitive}(\.{"vfuzz"},\39\\{assign\_dimen},\39\\{dimen\_base}+\\{vfuzz%
\_code})$;\6
$\\{primitive}(\.{"delimitershortfall"},\39\\{assign\_dimen},\39\\{dimen%
\_base}+\\{delimiter\_shortfall\_code})$;\6
$\\{primitive}(\.{"nulldelimiterspace"},\39\\{assign\_dimen},\39\\{dimen%
\_base}+\\{null\_delimiter\_space\_code})$;\6
$\\{primitive}(\.{"scriptspace"},\39\\{assign\_dimen},\39\\{dimen\_base}+%
\\{script\_space\_code})$;\6
$\\{primitive}(\.{"predisplaysize"},\39\\{assign\_dimen},\39\\{dimen\_base}+%
\\{pre\_display\_size\_code})$;\6
$\\{primitive}(\.{"displaywidth"},\39\\{assign\_dimen},\39\\{dimen\_base}+%
\\{display\_width\_code})$;\6
$\\{primitive}(\.{"displayindent"},\39\\{assign\_dimen},\39\\{dimen\_base}+%
\\{display\_indent\_code})$;\6
$\\{primitive}(\.{"overfullrule"},\39\\{assign\_dimen},\39\\{dimen\_base}+%
\\{overfull\_rule\_code})$;\6
$\\{primitive}(\.{"hangindent"},\39\\{assign\_dimen},\39\\{dimen\_base}+\\{hang%
\_indent\_code})$;\6
$\\{primitive}(\.{"hoffset"},\39\\{assign\_dimen},\39\\{dimen\_base}+\\{h%
\_offset\_code})$;\6
$\\{primitive}(\.{"voffset"},\39\\{assign\_dimen},\39\\{dimen\_base}+\\{v%
\_offset\_code})$;\par
\fi

\M249. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{assign\_dimen}: \37\&{if} $\\{chr\_code}<\\{scaled\_base}$ \1\&{then}\5
$\\{print\_length\_param}(\\{chr\_code}-\\{dimen\_base})$\6
\4\&{else} \&{begin} \37$\\{print\_esc}(\.{"dimen"})$;\5
$\\{print\_int}(\\{chr\_code}-\\{scaled\_base})$;\6
\&{end};\2\par
\fi

\M250. \P$\X164:Initialize table entries (done by \.{INITEX} only)\X\mathrel{+}%
\S$\6
\&{for} $\|k\K\\{dimen\_base}\mathrel{\&{to}}\\{eqtb\_size}$ \1\&{do}\5
$\\{eqtb}[\|k].\\{sc}\K0$;\2\par
\fi

\M251. \P$\X251:Show equivalent \|n, in region 6\X\S$\6
\&{begin} \37\&{if} $\|n<\\{scaled\_base}$ \1\&{then}\5
$\\{print\_length\_param}(\|n-\\{dimen\_base})$\6
\4\&{else} \&{begin} \37$\\{print\_esc}(\.{"dimen"})$;\5
$\\{print\_int}(\|n-\\{scaled\_base})$;\6
\&{end};\2\6
$\\{print\_char}(\.{"="})$;\5
$\\{print\_scaled}(\\{eqtb}[\|n].\\{sc})$;\5
$\\{print}(\.{"pt"})$;\6
\&{end}\par
\U section~252.\fi

\M252. Here is a procedure that displays the contents of $\\{eqtb}[\|n]$
symbolically.

\Y\P\hbox{\4}\X298:Declare the procedure called \\{print\_cmd\_chr}\X\6
\&{stat} \37\&{procedure}\1\  \37$\\{show\_eqtb}(\|n:\\{pointer})$;\2\6
\&{begin} \37\&{if} $\|n<\\{active\_base}$ \1\&{then}\5
$\\{print\_char}(\.{"?"})$\C{this can't happen}\6
\4\&{else} \&{if} $\|n<\\{glue\_base}$ \1\&{then}\5
\X223:Show equivalent \|n, in region 1 or 2\X\6
\4\&{else} \&{if} $\|n<\\{local\_base}$ \1\&{then}\5
\X229:Show equivalent \|n, in region 3\X\6
\4\&{else} \&{if} $\|n<\\{int\_base}$ \1\&{then}\5
\X233:Show equivalent \|n, in region 4\X\6
\4\&{else} \&{if} $\|n<\\{dimen\_base}$ \1\&{then}\5
\X242:Show equivalent \|n, in region 5\X\6
\4\&{else} \&{if} $\|n\L\\{eqtb\_size}$ \1\&{then}\5
\X251:Show equivalent \|n, in region 6\X\6
\4\&{else} $\\{print\_char}(\.{"?"})$;\C{this can't happen either}\2\2\2\2\2\2\6
\&{end};\6
\&{tats}\par
\fi

\M253. The last two regions of \\{eqtb} have fullword values instead of the
three fields \\{eq\_level}, \\{eq\_type}, and \\{equiv}. An \\{eq\_type} is
unnecessary,
but \TeX\ needs to store the \\{eq\_level} information in another array
called \\{xeq\_level}.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{eqtb}: \37\&{array} $[\\{active\_base}\to\\{eqtb\_size}]$ \1\&{of}\5
\\{memory\_word};\2\6
\4\\{xeq\_level}: \37\&{array} $[\\{int\_base}\to\\{eqtb\_size}]$ \1\&{of}\5
\\{quarterword};\2\par
\fi

\M254. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
\&{for} $\|k\K\\{int\_base}\mathrel{\&{to}}\\{eqtb\_size}$ \1\&{do}\5
$\\{xeq\_level}[\|k]\K\\{level\_one}$;\2\par
\fi

\M255. When the debugging routine \\{search\_mem} is looking for pointers
having a
given value, it is interested only in regions 1 to~3 of~\\{eqtb}, and in the
first part of region~4.

\Y\P$\4\X255:Search \\{eqtb} for equivalents equal to \|p\X\S$\6
\&{for} $\|q\K\\{active\_base}\mathrel{\&{to}}\\{box\_base}+255$ \1\&{do}\6
\&{begin} \37\&{if} $\\{equiv}(\|q)=\|p$ \1\&{then}\6
\&{begin} \37$\\{print\_nl}(\.{"EQUIV("})$;\5
$\\{print\_int}(\|q)$;\5
$\\{print\_char}(\.{")"})$;\6
\&{end};\2\6
\&{end}\2\par
\U section~172.\fi

\N256.  \[18] The hash table.
Control sequences are stored and retrieved by means of a fairly standard hash
table algorithm called the method of ``coalescing lists'' (cf.\ Algorithm 6.4C
in {\sl The Art of Computer Programming\/}). Once a control sequence enters the
table, it is never removed, because there are complicated situations
involving \.{\\gdef} where the removal of a control sequence at the end of
a group would be a mistake preventable only by the introduction of a
complicated reference-count mechanism.

The actual sequence of letters forming a control sequence identifier is
stored in the \\{str\_pool} array together with all the other strings. An
auxiliary array \\{hash} consists of items with two halfword fields per
word. The first of these, called $\\{next}(\|p)$, points to the next identifier
belonging to the same coalesced list as the identifier corresponding to~\|p;
and the other, called $\\{text}(\|p)$, points to the \\{str\_start} entry for
\|p's identifier. If position~\|p of the hash table is empty, we have
$\\{text}(\|p)=0$; if position \|p is either empty or the end of a coalesced
hash list, we have $\\{next}(\|p)=0$. An auxiliary pointer variable called
\\{hash\_used} is maintained in such a way that all locations $\|p\G\\{hash%
\_used}$
are nonempty. The global variable \\{cs\_count} tells how many multiletter
control sequences have been defined, if statistics are being kept.

A global boolean variable called \\{no\_new\_control\_sequence} is set to
\\{true} during the time that new hash table entries are forbidden.

\Y\P\D \37$\\{next}(\#)\S\\{hash}[\#].\\{lh}$\C{link for coalesced lists}\par
\P\D \37$\\{text}(\#)\S\\{hash}[\#].\\{rh}$\C{string number for control
sequence name}\par
\P\D \37$\\{hash\_is\_full}\S(\\{hash\_used}=\\{hash\_base})$\C{test if all
positions are occupied}\par
\P\D \37$\\{font\_id\_text}(\#)\S\\{text}(\\{font\_id\_base}+\#)$\C{a frozen
font identifier's name}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{hash}: \37\&{array} $[\\{hash\_base}\to\\{undefined\_control%
\_sequence}-1]$ \1\&{of}\5
\\{two\_halves};\C{the hash table}\2\6
\4\\{hash\_used}: \37\\{pointer};\C{allocation pointer for \\{hash}}\6
\4\\{no\_new\_control\_sequence}: \37\\{boolean};\C{are new identifiers legal?}%
\6
\4\\{cs\_count}: \37\\{integer};\C{total number of known identifiers}\par
\fi

\M257. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{no\_new\_control\_sequence}\K\\{true}$;\C{new identifiers are usually
forbidden}\6
$\\{next}(\\{hash\_base})\K0$;\5
$\\{text}(\\{hash\_base})\K0$;\6
\&{for} $\|k\K\\{hash\_base}+1\mathrel{\&{to}}\\{undefined\_control%
\_sequence}-1$ \1\&{do}\5
$\\{hash}[\|k]\K\\{hash}[\\{hash\_base}]$;\2\par
\fi

\M258. \P$\X164:Initialize table entries (done by \.{INITEX} only)\X\mathrel{+}%
\S$\6
$\\{hash\_used}\K\\{frozen\_control\_sequence}$;\C{nothing is used}\6
$\\{cs\_count}\K0$;\5
$\\{eq\_type}(\\{frozen\_dont\_expand})\K\\{dont\_expand}$;\5
$\\{text}(\\{frozen\_dont\_expand})\K\.{"notexpanded:"}$;\par
\fi

\M259. Here is the subroutine that searches the hash table for an identifier
that matches a given string of length $\|l>1$ appearing in $\\{buffer}[\|j\to(%
\|j+\|l-1)]$. If the identifier is found, the corresponding hash table address
is returned. Otherwise, if the global variable \\{no\_new\_control\_sequence}
is \\{true}, the dummy address \\{undefined\_control\_sequence} is returned.
Otherwise the identifier is inserted into the hash table and its location
is returned.

\Y\P\4\&{function}\1\  \37$\\{id\_lookup}(\|j,\39\|l:\\{integer})$: \37%
\\{pointer};\C{search the hash table}\6
\4\&{label} \37\\{found};\C{go here if you found it}\6
\4\&{var} \37\|h: \37\\{integer};\C{hash code}\6
\|p: \37\\{pointer};\C{index in \\{hash} array}\6
\|k: \37\\{pointer};\C{index in \\{buffer} array}\2\6
\&{begin} \37\X261:Compute the hash code \|h\X;\6
$\|p\K\|h+\\{hash\_base}$;\C{we start searching here; note that $0\L\|h<\\{hash%
\_prime}$}\6
\~ \1\&{loop}\ \&{begin} \37\&{if} $\\{text}(\|p)>0$ \1\&{then}\6
\&{if} $\\{length}(\\{text}(\|p))=\|l$ \1\&{then}\6
\&{if} $\\{str\_eq\_buf}(\\{text}(\|p),\39\|j)$ \1\&{then}\5
\&{goto} \37\\{found};\2\2\2\6
\&{if} $\\{next}(\|p)=0$ \1\&{then}\6
\&{begin} \37\&{if} $\\{no\_new\_control\_sequence}$ \1\&{then}\5
$\|p\K\\{undefined\_control\_sequence}$\6
\4\&{else} \X260:Insert a new control sequence after \|p, then make \|p point
to it\X;\2\6
\&{goto} \37\\{found};\6
\&{end};\2\6
$\|p\K\\{next}(\|p)$;\6
\&{end};\2\6
\4\\{found}: \37$\\{id\_lookup}\K\|p$;\6
\&{end};\par
\fi

\M260. \P$\X260:Insert a new control sequence after \|p, then make \|p point to
it\X\S$\6
\&{begin} \37\&{if} $\\{text}(\|p)>0$ \1\&{then}\6
\&{begin} \37\1\&{repeat} \37\&{if} $\\{hash\_is\_full}$ \1\&{then}\5
$\\{overflow}(\.{"hash\ size"},\39\\{hash\_size})$;\2\6
$\\{decr}(\\{hash\_used})$;\6
\4\&{until}\5
$\\{text}(\\{hash\_used})=0$;\C{search for an empty location in \\{hash}}\2\6
$\\{next}(\|p)\K\\{hash\_used}$;\5
$\|p\K\\{hash\_used}$;\6
\&{end};\2\6
$\\{str\_room}(\|l)$;\6
\&{for} $\|k\K\|j\mathrel{\&{to}}\|j+\|l-1$ \1\&{do}\5
$\\{append\_char}(\\{buffer}[\|k])$;\2\6
$\\{text}(\|p)\K\\{make\_string}$;\6
\&{stat} \37$\\{incr}(\\{cs\_count})$;\ \&{tats}\6
\&{end}\par
\U section~259.\fi

\M261. The value of \\{hash\_prime} should be roughly 85\% of \\{hash\_size},
and it
should be a prime number.  The theory of hashing tells us to expect fewer
than two table probes, on the average, when the search is successful.
[See J.~S. Vitter, {\sl Journal of the ACM\/ \bf30} (1983), 231--258.]

\Y\P$\4\X261:Compute the hash code \|h\X\S$\6
$\|h\K\\{buffer}[\|j]$;\6
\&{for} $\|k\K\|j+1\mathrel{\&{to}}\|j+\|l-1$ \1\&{do}\6
\&{begin} \37$\|h\K\|h+\|h+\\{buffer}[\|k]$;\6
\&{while} $\|h\G\\{hash\_prime}$ \1\&{do}\5
$\|h\K\|h-\\{hash\_prime}$;\2\6
\&{end}\2\par
\U section~259.\fi

\M262. Single-character control sequences do not need to be looked up in a hash
table, since we can use the character code itself as a direct address.
The procedure \\{print\_cs} prints the name of a control sequence, given
a pointer to its address in \\{eqtb}. A space is printed after the name
unless it is a single nonletter or an active character. This procedure
might be invoked with invalid data, so it is ``extra robust.'' The
individual characters must be printed one at a time using \\{print}, since
they may be unprintable.

\Y\P$\4\X57:Basic printing procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{print\_cs}(\|p:\\{integer})$;\C{prints a purported
control sequence}\2\6
\&{begin} \37\&{if} $\|p<\\{hash\_base}$ \1\&{then}\C{single character}\6
\&{if} $\|p\G\\{single\_base}$ \1\&{then}\6
\&{if} $\|p=\\{null\_cs}$ \1\&{then}\6
\&{begin} \37$\\{print\_esc}(\.{"csname"})$;\5
$\\{print\_esc}(\.{"endcsname"})$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{print\_esc}(\|p-\\{single\_base})$;\6
\&{if} $\\{cat\_code}(\|p-\\{single\_base})=\\{letter}$ \1\&{then}\5
$\\{print\_char}(\.{"\ "})$;\2\6
\&{end}\2\6
\4\&{else} \&{if} $\|p<\\{active\_base}$ \1\&{then}\5
$\\{print\_esc}(\.{"IMPOSSIBLE."})$\6
\4\&{else} $\\{print}(\|p-\\{active\_base})$\2\2\6
\4\&{else} \&{if} $\|p\G\\{undefined\_control\_sequence}$ \1\&{then}\5
$\\{print\_esc}(\.{"IMPOSSIBLE."})$\6
\4\&{else} \&{if} $(\\{text}(\|p)<0)\V(\\{text}(\|p)\G\\{str\_ptr})$ \1\&{then}%
\5
$\\{print\_esc}(\.{"NONEXISTENT."})$\6
\4\&{else} \&{begin} \37$\\{print\_esc}(\.{""})$;\5
$\\{slow\_print}(\\{text}(\|p))$;\5
$\\{print\_char}(\.{"\ "})$;\6
\&{end};\2\2\2\6
\&{end};\par
\fi

\M263. Here is a similar procedure; it avoids the error checks, and it never
prints a space after the control sequence.

\Y\P$\4\X57:Basic printing procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{sprint\_cs}(\|p:\\{pointer})$;\C{prints a control
sequence}\2\6
\&{begin} \37\&{if} $\|p<\\{hash\_base}$ \1\&{then}\6
\&{if} $\|p<\\{single\_base}$ \1\&{then}\5
$\\{print}(\|p-\\{active\_base})$\6
\4\&{else} \&{if} $\|p<\\{null\_cs}$ \1\&{then}\5
$\\{print\_esc}(\|p-\\{single\_base})$\6
\4\&{else} \&{begin} \37$\\{print\_esc}(\.{"csname"})$;\5
$\\{print\_esc}(\.{"endcsname"})$;\6
\&{end}\2\2\6
\4\&{else} \&{begin} \37$\\{print\_esc}(\.{""})$;\5
$\\{slow\_print}(\\{text}(\|p))$;\6
\&{end};\2\6
\&{end};\par
\fi

\M264. We need to put \TeX's ``primitive'' control sequences into the hash
table, together with their command code (which will be the \\{eq\_type})
and an operand (which will be the \\{equiv}). The \\{primitive} procedure
does this, in a way that no \TeX\ user can. The global value \\{cur\_val}
contains the new \\{eqtb} pointer after \\{primitive} has acted.

\Y\P\&{init} \37\&{procedure}\1\  \37$\\{primitive}(\|s:\\{str\_number};\,\35%
\|c:\\{quarterword};\,\35\|o:\\{halfword})$;\6
\4\&{var} \37\|k: \37\\{pool\_pointer};\C{index into \\{str\_pool}}\6
\|j: \37\\{small\_number};\C{index into \\{buffer}}\6
\|l: \37\\{small\_number};\C{length of the string}\2\6
\&{begin} \37\&{if} $\|s<128$ \1\&{then}\5
$\\{cur\_val}\K\|s+\\{single\_base}$\6
\4\&{else} \&{begin} \37$\|k\K\\{str\_start}[\|s]$;\5
$\|l\K\\{str\_start}[\|s+1]-\|k$;\C{we will move \|s into the (empty) %
\\{buffer}}\6
\&{for} $\|j\K0\mathrel{\&{to}}\|l-1$ \1\&{do}\5
$\\{buffer}[\|j]\K\\{str\_pool}[\|k+\|j]$;\2\6
$\\{cur\_val}\K\\{id\_lookup}(0,\39\|l)$;\C{\\{no\_new\_control\_sequence} is %
\\{false}}\6
\\{flush\_string};\5
$\\{text}(\\{cur\_val})\K\|s$;\C{we don't want to have the string twice}\6
\&{end};\2\6
$\\{eq\_level}(\\{cur\_val})\K\\{level\_one}$;\5
$\\{eq\_type}(\\{cur\_val})\K\|c$;\5
$\\{equiv}(\\{cur\_val})\K\|o$;\6
\&{end};\6
\&{tini}\par
\fi

\M265\*. Many of \TeX's primitives need no \\{equiv}, since they are
identifiable
by their \\{eq\_type} alone. These primitives are loaded into the hash table
as follows:

\Y\P$\4\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}\S$\6
$\\{primitive}(\.{"\ "},\39\\{ex\_space},\390)$;\6
$\\{primitive}(\.{"/"},\39\\{ital\_corr},\390)$;\6
$\\{primitive}(\.{"accent"},\39\\{accent},\390)$;\6
$\\{primitive}(\.{"advance"},\39\\{advance},\390)$;\6
$\\{primitive}(\.{"afterassignment"},\39\\{after\_assignment},\390)$;\6
$\\{primitive}(\.{"aftergroup"},\39\\{after\_group},\390)$;\6
$\\{primitive}(\.{"begingroup"},\39\\{begin\_group},\390)$;\6
$\\{primitive}(\.{"char"},\39\\{char\_num},\390)$;\6
$\\{primitive}(\.{"csname"},\39\\{cs\_name},\390)$;\6
$\\{primitive}(\.{"delimiter"},\39\\{delim\_num},\390)$;\6
$\\{primitive}(\.{"divide"},\39\\{divide},\390)$;\6
$\\{primitive}(\.{"endcsname"},\39\\{end\_cs\_name},\390)$;\6
$\\{primitive}(\.{"endgroup"},\39\\{end\_group},\390)$;\5
$\\{text}(\\{frozen\_end\_group})\K\.{"endgroup"}$;\5
$\\{eqtb}[\\{frozen\_end\_group}]\K\\{eqtb}[\\{cur\_val}]$;\6
$\\{primitive}(\.{"expandafter"},\39\\{expand\_after},\390)$;\6
$\\{primitive}(\.{"font"},\39\\{def\_font},\390)$;\6
$\\{primitive}(\.{"fontdimen"},\39\\{assign\_font\_dimen},\390)$;\6
$\\{primitive}(\.{"halign"},\39\\{halign},\390)$;\6
$\\{primitive}(\.{"hrule"},\39\\{hrule},\390)$;\6
$\\{primitive}(\.{"ignorespaces"},\39\\{ignore\_spaces},\390)$;\6
$\\{primitive}(\.{"insert"},\39\\{insert},\390)$;\6
$\\{primitive}(\.{"mark"},\39\\{mark},\390)$;\6
$\\{primitive}(\.{"mathaccent"},\39\\{math\_accent},\390)$;\6
$\\{primitive}(\.{"mathchar"},\39\\{math\_char\_num},\390)$;\6
$\\{primitive}(\.{"mathchoice"},\39\\{math\_choice},\390)$;\6
$\\{primitive}(\.{"multiply"},\39\\{multiply},\390)$;\6
$\\{primitive}(\.{"noalign"},\39\\{no\_align},\390)$;\6
$\\{primitive}(\.{"noexpand"},\39\\{no\_expand},\390)$;\6
$\\{primitive}(\.{"nonscript"},\39\\{non\_script},\390)$;\6
$\\{primitive}(\.{"omit"},\39\\{omit},\390)$;\6
$\\{primitive}(\.{"parshape"},\39\\{set\_shape},\390)$;\6
$\\{primitive}(\.{"penalty"},\39\\{break\_penalty},\390)$;\6
$\\{primitive}(\.{"prevgraf"},\39\\{set\_prev\_graf},\390)$;\6
$\\{primitive}(\.{"radical"},\39\\{radical},\390)$;\6
$\\{primitive}(\.{"read"},\39\\{read\_to\_cs},\390)$;\6
$\\{primitive}(\.{"relax"},\39\\{relax},\39256)$;\C{cf.\ \\{scan\_file\_name}}\6
$\\{text}(\\{frozen\_relax})\K\.{"relax"}$;\5
$\\{eqtb}[\\{frozen\_relax}]\K\\{eqtb}[\\{cur\_val}]$;\6
$\\{primitive}(\.{"setbox"},\39\\{set\_box},\390)$;\6
$\\{primitive}(\.{"the"},\39\\{the},\390)$;\6
$\\{primitive}(\.{"toks"},\39\\{toks\_register},\390)$;\6
$\\{primitive}(\.{"vadjust"},\39\\{vadjust},\390)$;\6
$\\{primitive}(\.{"valign"},\39\\{valign},\390)$;\6
$\\{primitive}(\.{"vcenter"},\39\\{vcenter},\390)$;\6
$\\{primitive}(\.{"vrule"},\39\\{vrule},\390)$;\6
$\\{primitive}(\.{"xchar"},\39\\{xchar\_num},\390)$;\par
\fi

\M266\*. Each primitive has a corresponding inverse, so that it is possible to
display the cryptic numeric contents of \\{eqtb} in symbolic form.
Every call of \\{primitive} in this program is therefore accompanied by some
straightforward code that forms part of the \\{print\_cmd\_chr} routine
explained below.

\Y\P$\4\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of primitives\X%
\mathrel{+}\S$\6
\4\\{accent}: \37$\\{print\_esc}(\.{"accent"})$;\6
\4\\{advance}: \37$\\{print\_esc}(\.{"advance"})$;\6
\4\\{after\_assignment}: \37$\\{print\_esc}(\.{"afterassignment"})$;\6
\4\\{after\_group}: \37$\\{print\_esc}(\.{"aftergroup"})$;\6
\4\\{assign\_font\_dimen}: \37$\\{print\_esc}(\.{"fontdimen"})$;\6
\4\\{begin\_group}: \37$\\{print\_esc}(\.{"begingroup"})$;\6
\4\\{break\_penalty}: \37$\\{print\_esc}(\.{"penalty"})$;\6
\4\\{char\_num}: \37$\\{print\_esc}(\.{"char"})$;\6
\4\\{cs\_name}: \37$\\{print\_esc}(\.{"csname"})$;\6
\4\\{def\_font}: \37$\\{print\_esc}(\.{"font"})$;\6
\4\\{delim\_num}: \37$\\{print\_esc}(\.{"delimiter"})$;\6
\4\\{divide}: \37$\\{print\_esc}(\.{"divide"})$;\6
\4\\{end\_cs\_name}: \37$\\{print\_esc}(\.{"endcsname"})$;\6
\4\\{end\_group}: \37$\\{print\_esc}(\.{"endgroup"})$;\6
\4\\{ex\_space}: \37$\\{print\_esc}(\.{"\ "})$;\6
\4\\{expand\_after}: \37$\\{print\_esc}(\.{"expandafter"})$;\6
\4\\{halign}: \37$\\{print\_esc}(\.{"halign"})$;\6
\4\\{hrule}: \37$\\{print\_esc}(\.{"hrule"})$;\6
\4\\{ignore\_spaces}: \37$\\{print\_esc}(\.{"ignorespaces"})$;\6
\4\\{insert}: \37$\\{print\_esc}(\.{"insert"})$;\6
\4\\{ital\_corr}: \37$\\{print\_esc}(\.{"/"})$;\6
\4\\{mark}: \37$\\{print\_esc}(\.{"mark"})$;\6
\4\\{math\_accent}: \37$\\{print\_esc}(\.{"mathaccent"})$;\6
\4\\{math\_char\_num}: \37$\\{print\_esc}(\.{"mathchar"})$;\6
\4\\{math\_choice}: \37$\\{print\_esc}(\.{"mathchoice"})$;\6
\4\\{multiply}: \37$\\{print\_esc}(\.{"multiply"})$;\6
\4\\{no\_align}: \37$\\{print\_esc}(\.{"noalign"})$;\6
\4\\{no\_expand}: \37$\\{print\_esc}(\.{"noexpand"})$;\6
\4\\{non\_script}: \37$\\{print\_esc}(\.{"nonscript"})$;\6
\4\\{omit}: \37$\\{print\_esc}(\.{"omit"})$;\6
\4\\{radical}: \37$\\{print\_esc}(\.{"radical"})$;\6
\4\\{read\_to\_cs}: \37$\\{print\_esc}(\.{"read"})$;\6
\4\\{relax}: \37$\\{print\_esc}(\.{"relax"})$;\6
\4\\{set\_box}: \37$\\{print\_esc}(\.{"setbox"})$;\6
\4\\{set\_prev\_graf}: \37$\\{print\_esc}(\.{"prevgraf"})$;\6
\4\\{set\_shape}: \37$\\{print\_esc}(\.{"parshape"})$;\6
\4\\{the}: \37$\\{print\_esc}(\.{"the"})$;\6
\4\\{toks\_register}: \37$\\{print\_esc}(\.{"toks"})$;\6
\4\\{vadjust}: \37$\\{print\_esc}(\.{"vadjust"})$;\6
\4\\{valign}: \37$\\{print\_esc}(\.{"valign"})$;\6
\4\\{vcenter}: \37$\\{print\_esc}(\.{"vcenter"})$;\6
\4\\{vrule}: \37$\\{print\_esc}(\.{"vrule"})$;\6
\4\\{xchar\_num}: \37$\\{print\_esc}(\.{"xchar"})$;\par
\fi

\M267. We will deal with the other primitives later, at some point in the
program
where their \\{eq\_type} and \\{equiv} values are more meaningful.  For
example,
the primitives for math mode will be loaded when we consider the routines
that deal with formulas. It is easy to find where each particular
primitive was treated by looking in the index at the end; for example, the
section where \.{"radical"} entered \\{eqtb} is listed under `\.{\\radical}
primitive'. (Primitives consisting of a single nonalphabetic character,
like `\.{\\/}', are listed under `Single-character primitives'.)

Meanwhile, this is a convenient place to catch up on something we were unable
to do before the hash table was defined:

\Y\P$\4\X267:Print the font identifier for $\\{font}(\|p)$\X\S$\6
$\\{print\_esc}(\\{font\_id\_text}(\\{font}(\|p)))$\par
\U sections~174\* and~176\*.\fi

\N268.  \[19] Saving and restoring equivalents.
The nested structure provided by `$\.{\char'173}\ldots\.{\char'175}$' groups
in \TeX\ means that \\{eqtb} entries valid in outer groups should be saved
and restored later if they are overridden inside the braces. When a new %
\\{eqtb}
value is being assigned, the program therefore checks to see if the previous
entry belongs to an outer level. In such a case, the old value is placed
on the \\{save\_stack} just before the new value enters \\{eqtb}. At the
end of a grouping level, i.e., when the right brace is sensed, the
\\{save\_stack} is used to restore the outer values, and the inner ones are
destroyed.

Entries on the \\{save\_stack} are of type \\{memory\_word}. The top item on
this stack is $\\{save\_stack}[\|p]$, where $\|p=\\{save\_ptr}-1$; it contains
three
fields called \\{save\_type}, \\{save\_level}, and \\{save\_index}, and it is
interpreted in one of four ways:

\yskip\hang 1) If $\\{save\_type}(\|p)=\\{restore\_old\_value}$, then
$\\{save\_index}(\|p)$ is a location in \\{eqtb} whose current value should
be destroyed at the end of the current group and replaced by $\\{save\_stack}[%
\|p-1]$.
Furthermore if $\\{save\_index}(\|p)\G\\{int\_base}$, then $\\{save\_level}(%
\|p)$
should replace the corresponding entry in \\{xeq\_level}.

\yskip\hang 2) If $\\{save\_type}(\|p)=\\{restore\_zero}$, then $\\{save%
\_index}(\|p)$
is a location in \\{eqtb} whose current value should be destroyed at the end
of the current group and replaced by $\\{eqtb}[\\{undefined\_control%
\_sequence}]$.

\yskip\hang 3) If $\\{save\_type}(\|p)=\\{insert\_token}$, then $\\{save%
\_index}(\|p)$
is a token that should be inserted into \TeX's input when the current
group ends.

\yskip\hang 4) If $\\{save\_type}(\|p)=\\{level\_boundary}$, then $\\{save%
\_level}(\|p)$
is a code explaining what kind of group we were previously in, and
$\\{save\_index}(\|p)$ points to the level boundary word at the bottom of
the entries for that group.

\Y\P\D \37$\\{save\_type}(\#)\S\\{save\_stack}[\#].\\{hh}.\\{b0}$\C{classifies
a \\{save\_stack} entry}\par
\P\D \37$\\{save\_level}(\#)\S\\{save\_stack}[\#].\\{hh}.\\{b1}$\C{saved level
for regions 5 and 6, or group code}\par
\P\D \37$\\{save\_index}(\#)\S\\{save\_stack}[\#].\\{hh}.\\{rh}$\C{\\{eqtb}
location or \\{save\_stack} location}\par
\P\D \37$\\{restore\_old\_value}=0$\C{\\{save\_type} when a value should be
restored later}\par
\P\D \37$\\{restore\_zero}=1$\C{\\{save\_type} when an undefined entry should
be restored}\par
\P\D \37$\\{insert\_token}=2$\C{\\{save\_type} when a token is being saved for
later use}\par
\P\D \37$\\{level\_boundary}=3$\C{\\{save\_type} corresponding to beginning of
group}\par
\fi

\M269. Here are the group codes that are used to discriminate between different
kinds of groups. They allow \TeX\ to decide what special actions, if any,
should be performed when a group ends.
\def\grp{\.{\char'173...\char'175}}

Some groups are not supposed to be ended by right braces. For example,
the `\.\$' that begins a math formula causes a \\{math\_shift\_group} to
be started, and this should be terminated by a matching `\.\$'. Similarly,
a group that starts with \.{\\left} should end with \.{\\right}, and
one that starts with \.{\\begingroup} should end with \.{\\endgroup}.

\Y\P\D \37$\\{bottom\_level}=0$\C{group code for the outside world}\par
\P\D \37$\\{simple\_group}=1$\C{group code for local structure only}\par
\P\D \37$\\{hbox\_group}=2$\C{code for `\.{\\hbox}\grp'}\par
\P\D \37$\\{adjusted\_hbox\_group}=3$\C{code for `\.{\\hbox}\grp' in vertical
mode}\par
\P\D \37$\\{vbox\_group}=4$\C{code for `\.{\\vbox}\grp'}\par
\P\D \37$\\{vtop\_group}=5$\C{code for `\.{\\vtop}\grp'}\par
\P\D \37$\\{align\_group}=6$\C{code for `\.{\\halign}\grp', `\.{\\valign}\grp'}%
\par
\P\D \37$\\{no\_align\_group}=7$\C{code for `\.{\\noalign}\grp'}\par
\P\D \37$\\{output\_group}=8$\C{code for output routine}\par
\P\D \37$\\{math\_group}=9$\C{code for, e.g, `\.{\char'136}\grp'}\par
\P\D \37$\\{disc\_group}=10$\C{code for `\.{\\discretionary}\grp\grp\grp'}\par
\P\D \37$\\{insert\_group}=11$\C{code for `\.{\\insert}\grp', `\.{\\vadjust}%
\grp'}\par
\P\D \37$\\{vcenter\_group}=12$\C{code for `\.{\\vcenter}\grp'}\par
\P\D \37$\\{math\_choice\_group}=13$\C{code for `\.{\\mathchoice}\grp\grp\grp%
\grp'}\par
\P\D \37$\\{semi\_simple\_group}=14$\C{code for `\.{\\begingroup...%
\\endgroup}'}\par
\P\D \37$\\{math\_shift\_group}=15$\C{code for `\.{\$...\$}'}\par
\P\D \37$\\{math\_left\_group}=16$\C{code for `\.{\\left...\\right}'}\par
\P\D \37$\\{max\_group\_code}=16$\par
\Y\P$\4\X18:Types in the outer block\X\mathrel{+}\S$\6
$\\{group\_code}=0\to\\{max\_group\_code}$;\C{\\{save\_index} for a level
boundary}\par
\fi

\M270. The global variable \\{cur\_group} keeps track of what sort of group we
are
currently in. Another global variable, \\{cur\_boundary}, points to the
topmost \\{level\_boundary} word.  And \\{cur\_level} is the current depth of
nesting. The routines are designed to preserve the condition that no entry
in the \\{save\_stack} or in \\{eqtb} ever has a level greater than \\{cur%
\_level}.

\fi

\M271. \P$\X13:Global variables\X\mathrel{+}\S$\6
\4\\{save\_stack}: \37\&{array} $[0\to\\{save\_size}]$ \1\&{of}\5
\\{memory\_word};\2\6
\4\\{save\_ptr}: \37$0\to\\{save\_size}$;\C{first unused entry on \\{save%
\_stack}}\6
\4\\{max\_save\_stack}: \37$0\to\\{save\_size}$;\C{maximum usage of save stack}%
\6
\4\\{cur\_level}: \37\\{quarterword};\C{current nesting level for groups}\6
\4\\{cur\_group}: \37\\{group\_code};\C{current group type}\6
\4\\{cur\_boundary}: \37$0\to\\{save\_size}$;\C{where the current level begins}%
\par
\fi

\M272. At this time it might be a good idea for the reader to review the
introduction
to \\{eqtb} that was given above just before the long lists of parameter names.
Recall that the ``outer level'' of the program is \\{level\_one}, since
undefined control sequences are assumed to be ``defined'' at \\{level\_zero}.

\Y\P$\4\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{save\_ptr}\K0$;\5
$\\{cur\_level}\K\\{level\_one}$;\5
$\\{cur\_group}\K\\{bottom\_level}$;\5
$\\{cur\_boundary}\K0$;\5
$\\{max\_save\_stack}\K0$;\par
\fi

\M273. The following macro is used to test if there is room for up to six more
entries on \\{save\_stack}. By making a conservative test like this, we can
get by with testing for overflow in only a few places.

\Y\P\D \37$\\{check\_full\_save\_stack}\S$\1\6
\&{if} $\\{save\_ptr}>\\{max\_save\_stack}$ \1\&{then}\6
\&{begin} \37$\\{max\_save\_stack}\K\\{save\_ptr}$;\6
\&{if} $\\{max\_save\_stack}>\\{save\_size}-6$ \1\&{then}\5
$\\{overflow}(\.{"save\ size"},\39\\{save\_size})$;\2\6
\&{end}\2\2\par
\fi

\M274. Procedure \\{new\_save\_level} is called when a group begins. The
argument is a group identification code like `\\{hbox\_group}'. After
calling this routine, it is safe to put five more entries on \\{save\_stack}.

In some cases a few integer-valued items are placed onto the
\\{save\_stack} just below a \\{level\_boundary} word, because this is a
convenient place to keep information that is supposed to ``pop up'' just
when the group has finished.
For example, when `\.{\\hbox to 100pt}\grp' is being treated, the 100pt
dimension is stored on \\{save\_stack} just before \\{new\_save\_level} is
called.

We use the notation $\\{saved}(\|k)$ to stand for an integer item that
appears in location $\\{save\_ptr}+\|k$ of the save stack.

\Y\P\D \37$\\{saved}(\#)\S\\{save\_stack}[\\{save\_ptr}+\#].\\{int}$\par
\Y\P\4\&{procedure}\1\  \37$\\{new\_save\_level}(\|c:\\{group\_code})$;\C{begin
a new level of grouping}\2\6
\&{begin} \37\\{check\_full\_save\_stack};\5
$\\{save\_type}(\\{save\_ptr})\K\\{level\_boundary}$;\5
$\\{save\_level}(\\{save\_ptr})\K\\{cur\_group}$;\5
$\\{save\_index}(\\{save\_ptr})\K\\{cur\_boundary}$;\6
\&{if} $\\{cur\_level}=\\{max\_quarterword}$ \1\&{then}\5
$\\{overflow}(\.{"grouping\ levels"},\39\\{max\_quarterword}-\\{min%
\_quarterword})$;\C{quit if $(\\{cur\_level}+1)$ is too big to be stored in %
\\{eqtb}}\2\6
$\\{cur\_boundary}\K\\{save\_ptr}$;\5
$\\{incr}(\\{cur\_level})$;\5
$\\{incr}(\\{save\_ptr})$;\5
$\\{cur\_group}\K\|c$;\6
\&{end};\par
\fi

\M275. Just before an entry of \\{eqtb} is changed, the following procedure
should
be called to update the other data structures properly. It is important
to keep in mind that reference counts in \\{mem} include references from
within \\{save\_stack}, so these counts must be handled carefully.

\Y\P\4\&{procedure}\1\  \37$\\{eq\_destroy}(\|w:\\{memory\_word})$;\C{gets
ready to forget \|w}\6
\4\&{var} \37\|q: \37\\{pointer};\C{\\{equiv} field of \|w}\2\6
\&{begin} \37\&{case} $\\{eq\_type\_field}(\|w)$ \1\&{of}\6
\4$\\{call},\39\\{long\_call},\39\\{outer\_call},\39\\{long\_outer\_call}$: %
\37$\\{delete\_token\_ref}(\\{equiv\_field}(\|w))$;\6
\4\\{glue\_ref}: \37$\\{delete\_glue\_ref}(\\{equiv\_field}(\|w))$;\6
\4\\{shape\_ref}: \37\&{begin} \37$\|q\K\\{equiv\_field}(\|w)$;\C{we need to
free a \.{\\parshape} block}\6
\&{if} $\|q\I\\{null}$ \1\&{then}\5
$\\{free\_node}(\|q,\39\\{info}(\|q)+\\{info}(\|q)+1)$;\2\6
\&{end};\C{such a block is $2\|n+1$ words long, where $\|n=\\{info}(\|q)$}\6
\4\\{box\_ref}: \37$\\{flush\_node\_list}(\\{equiv\_field}(\|w))$;\6
\4\&{othercases} \37\\{do\_nothing}\2\6
\&{endcases};\6
\&{end};\par
\fi

\M276. To save a value of $\\{eqtb}[\|p]$ that was established at level \|l, we
can use the following subroutine.

\Y\P\4\&{procedure}\1\  \37$\\{eq\_save}(\|p:\\{pointer};\,\35\|l:%
\\{quarterword})$;\C{saves $\\{eqtb}[\|p]$}\2\6
\&{begin} \37\\{check\_full\_save\_stack};\6
\&{if} $\|l=\\{level\_zero}$ \1\&{then}\5
$\\{save\_type}(\\{save\_ptr})\K\\{restore\_zero}$\6
\4\&{else} \&{begin} \37$\\{save\_stack}[\\{save\_ptr}]\K\\{eqtb}[\|p]$;\5
$\\{incr}(\\{save\_ptr})$;\5
$\\{save\_type}(\\{save\_ptr})\K\\{restore\_old\_value}$;\6
\&{end};\2\6
$\\{save\_level}(\\{save\_ptr})\K\|l$;\5
$\\{save\_index}(\\{save\_ptr})\K\|p$;\5
$\\{incr}(\\{save\_ptr})$;\6
\&{end};\par
\fi

\M277. The procedure \\{eq\_define} defines an \\{eqtb} entry having specified
\\{eq\_type} and \\{equiv} fields, and saves the former value if appropriate.
This procedure is used only for entries in the first four regions of \\{eqtb},
i.e., only for entries that have \\{eq\_type} and \\{equiv} fields.
After calling this routine, it is safe to put four more entries on
\\{save\_stack}, provided that there was room for four more entries before
the call, since \\{eq\_save} makes the necessary test.

\Y\P\4\&{procedure}\1\  \37$\\{eq\_define}(\|p:\\{pointer};\,\35\|t:%
\\{quarterword};\,\35\|e:\\{halfword})$;\C{new data for \\{eqtb}}\2\6
\&{begin} \37\&{if} $\\{eq\_level}(\|p)=\\{cur\_level}$ \1\&{then}\5
$\\{eq\_destroy}(\\{eqtb}[\|p])$\6
\4\&{else} \&{if} $\\{cur\_level}>\\{level\_one}$ \1\&{then}\5
$\\{eq\_save}(\|p,\39\\{eq\_level}(\|p))$;\2\2\6
$\\{eq\_level}(\|p)\K\\{cur\_level}$;\5
$\\{eq\_type}(\|p)\K\|t$;\5
$\\{equiv}(\|p)\K\|e$;\6
\&{end};\par
\fi

\M278. The counterpart of \\{eq\_define} for the remaining (fullword) positions
in
\\{eqtb} is called \\{eq\_word\_define}. Since $\\{xeq\_level}[\|p]\G\\{level%
\_one}$ for all
\|p, a `\\{restore\_zero}' will never be used in this case.

\Y\P\4\&{procedure}\1\  \37$\\{eq\_word\_define}(\|p:\\{pointer};\,\35\|w:%
\\{integer})$;\2\6
\&{begin} \37\&{if} $\\{xeq\_level}[\|p]\I\\{cur\_level}$ \1\&{then}\6
\&{begin} \37$\\{eq\_save}(\|p,\39\\{xeq\_level}[\|p])$;\5
$\\{xeq\_level}[\|p]\K\\{cur\_level}$;\6
\&{end};\2\6
$\\{eqtb}[\|p].\\{int}\K\|w$;\6
\&{end};\par
\fi

\M279. The \\{eq\_define} and \\{eq\_word\_define} routines take care of local
definitions.
Global definitions are done in almost the same way, but there is no need
to save old values, and the new value is associated with \\{level\_one}.

\Y\P\4\&{procedure}\1\  \37$\\{geq\_define}(\|p:\\{pointer};\,\35\|t:%
\\{quarterword};\,\35\|e:\\{halfword})$;\C{global \\{eq\_define}}\2\6
\&{begin} \37$\\{eq\_destroy}(\\{eqtb}[\|p])$;\5
$\\{eq\_level}(\|p)\K\\{level\_one}$;\5
$\\{eq\_type}(\|p)\K\|t$;\5
$\\{equiv}(\|p)\K\|e$;\6
\&{end};\7
\4\&{procedure}\1\  \37$\\{geq\_word\_define}(\|p:\\{pointer};\,\35\|w:%
\\{integer})$;\C{global \\{eq\_word\_define}}\2\6
\&{begin} \37$\\{eqtb}[\|p].\\{int}\K\|w$;\5
$\\{xeq\_level}[\|p]\K\\{level\_one}$;\6
\&{end};\par
\fi

\M280. Subroutine \\{save\_for\_after} puts a token on the stack for
save-keeping.

\Y\P\4\&{procedure}\1\  \37$\\{save\_for\_after}(\|t:\\{halfword})$;\2\6
\&{begin} \37\\{check\_full\_save\_stack};\5
$\\{save\_type}(\\{save\_ptr})\K\\{insert\_token}$;\5
$\\{save\_level}(\\{save\_ptr})\K\\{level\_zero}$;\5
$\\{save\_index}(\\{save\_ptr})\K\|t$;\5
$\\{incr}(\\{save\_ptr})$;\6
\&{end};\par
\fi

\M281. The \\{unsave} routine goes the other way, taking items off of \\{save%
\_stack}.
This routine takes care of restoration when a level ends; everything
belonging to the topmost group is cleared off of the save stack.

\Y\P\hbox{\4}\X284:Declare the procedure called \\{restore\_trace}\X\6
\4\&{procedure}\1\  \37\\{back\_input};\5
\\{forward}; \hbox{\2} \6
\4\&{procedure}\1\  \37\\{unsave};\C{pops the top level off the save stack}\6
\4\&{label} \37\\{done};\6
\4\&{var} \37\|p: \37\\{pointer};\C{position to be restored}\6
\|l: \37\\{quarterword};\C{saved level, if in fullword regions of \\{eqtb}}\6
\|t: \37\\{halfword};\C{saved value of \\{cur\_tok}}\2\6
\&{begin} \37\&{if} $\\{cur\_level}>\\{level\_one}$ \1\&{then}\6
\&{begin} \37$\\{decr}(\\{cur\_level})$;\5
\X282:Clear off top level from \\{save\_stack}\X;\6
\&{end}\6
\4\&{else} $\\{confusion}(\.{"curlevel"})$;\C{\\{unsave} is not used when $%
\\{cur\_group}=\\{bottom\_level}$}\2\6
\&{end};\par
\fi

\M282. \P$\X282:Clear off top level from \\{save\_stack}\X\S$\6
\~ \1\&{loop}\ \&{begin} \37$\\{decr}(\\{save\_ptr})$;\6
\&{if} $\\{save\_type}(\\{save\_ptr})=\\{level\_boundary}$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
$\|p\K\\{save\_index}(\\{save\_ptr})$;\6
\&{if} $\\{save\_type}(\\{save\_ptr})=\\{insert\_token}$ \1\&{then}\5
\X326:Insert token \|p into \TeX's input\X\6
\4\&{else} \&{begin} \37\&{if} $\\{save\_type}(\\{save\_ptr})=\\{restore\_old%
\_value}$ \1\&{then}\6
\&{begin} \37$\|l\K\\{save\_level}(\\{save\_ptr})$;\5
$\\{decr}(\\{save\_ptr})$;\6
\&{end}\6
\4\&{else} $\\{save\_stack}[\\{save\_ptr}]\K\\{eqtb}[\\{undefined\_control%
\_sequence}]$;\2\6
\X283:Store \(s)$\\{save\_stack}[\\{save\_ptr}]$ in $\\{eqtb}[\|p]$, unless $%
\\{eqtb}[\|p]$ holds a global value\X;\6
\&{end};\2\6
\&{end};\2\6
\4\\{done}: \37$\\{cur\_group}\K\\{save\_level}(\\{save\_ptr})$;\5
$\\{cur\_boundary}\K\\{save\_index}(\\{save\_ptr})$\par
\U section~281.\fi

\M283. A global definition, which sets the level to \\{level\_one},
will not be undone by \\{unsave}. If at least one global definition of
$\\{eqtb}[\|p]$ has been carried out within the group that just ended, the
last such definition will therefore survive.

\Y\P$\4\X283:Store \(s)$\\{save\_stack}[\\{save\_ptr}]$ in $\\{eqtb}[\|p]$,
unless $\\{eqtb}[\|p]$ holds a global value\X\S$\6
\&{if} $\|p<\\{int\_base}$ \1\&{then}\6
\&{if} $\\{eq\_level}(\|p)=\\{level\_one}$ \1\&{then}\6
\&{begin} \37$\\{eq\_destroy}(\\{save\_stack}[\\{save\_ptr}])$;\C{destroy the
saved value}\6
\&{stat} \37\&{if} $\\{tracing\_restores}>0$ \1\&{then}\5
$\\{restore\_trace}(\|p,\39\.{"retaining"})$;\ \2\6
\&{tats}\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{eq\_destroy}(\\{eqtb}[\|p])$;\C{destroy the current
value}\6
$\\{eqtb}[\|p]\K\\{save\_stack}[\\{save\_ptr}]$;\C{restore the saved value}\6
\&{stat} \37\&{if} $\\{tracing\_restores}>0$ \1\&{then}\5
$\\{restore\_trace}(\|p,\39\.{"restoring"})$;\ \2\6
\&{tats}\6
\&{end}\2\6
\4\&{else} \&{if} $\\{xeq\_level}[\|p]\I\\{level\_one}$ \1\&{then}\6
\&{begin} \37$\\{eqtb}[\|p]\K\\{save\_stack}[\\{save\_ptr}]$;\5
$\\{xeq\_level}[\|p]\K\|l$;\6
\&{stat} \37\&{if} $\\{tracing\_restores}>0$ \1\&{then}\5
$\\{restore\_trace}(\|p,\39\.{"restoring"})$;\ \2\6
\&{tats}\6
\&{end}\6
\4\&{else} \&{begin} \37\&{stat} \37\&{if} $\\{tracing\_restores}>0$ \1\&{then}%
\5
$\\{restore\_trace}(\|p,\39\.{"retaining"})$;\ \2\6
\&{tats}\6
\&{end}\2\2\par
\U section~282.\fi

\M284. \P$\X284:Declare the procedure called \\{restore\_trace}\X\S$\6
\&{stat} \37\&{procedure}\1\  \37$\\{restore\_trace}(\|p:\\{pointer};\,\35\|s:%
\\{str\_number})$;\C{$\\{eqtb}[\|p]$ has just been restored or retained}\2\6
\&{begin} \37\\{begin\_diagnostic};\5
$\\{print\_char}(\.{"\{"})$;\5
$\\{print}(\|s)$;\5
$\\{print\_char}(\.{"\ "})$;\5
$\\{show\_eqtb}(\|p)$;\5
$\\{print\_char}(\.{"\}"})$;\5
$\\{end\_diagnostic}(\\{false})$;\6
\&{end};\6
\&{tats}\par
\U section~281.\fi

\M285. When looking for possible pointers to a memory location, it is helpful
to look for references from \\{eqtb} that might be waiting on the
save stack. Of course, we might find spurious pointers too; but this
routine is merely an aid when debugging, and at such times we are
grateful for any scraps of information, even if they prove to be irrelevant.

\Y\P$\4\X285:Search \\{save\_stack} for equivalents that point to \|p\X\S$\6
\&{if} $\\{save\_ptr}>0$ \1\&{then}\6
\&{for} $\|q\K0\mathrel{\&{to}}\\{save\_ptr}-1$ \1\&{do}\6
\&{begin} \37\&{if} $\\{equiv\_field}(\\{save\_stack}[\|q])=\|p$ \1\&{then}\6
\&{begin} \37$\\{print\_nl}(\.{"SAVE("})$;\5
$\\{print\_int}(\|q)$;\5
$\\{print\_char}(\.{")"})$;\6
\&{end};\2\6
\&{end}\2\2\par
\U section~172.\fi

\M286. Most of the parameters kept in \\{eqtb} can be changed freely, but
there's
an exception:  The magnification should not be used with two different
values during any \TeX\ job, since a single magnification is applied to an
entire run. The global variable \\{mag\_set} is set to the current
magnification
whenever it becomes necessary to ``freeze'' it at a particular value.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{mag\_set}: \37\\{integer};\C{if nonzero, this magnification should be used
henceforth}\par
\fi

\M287. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{mag\_set}\K0$;\par
\fi

\M288. The \\{prepare\_mag} subroutine is called whenever \TeX\ wants to use %
\\{mag}
for magnification.

\Y\P\4\&{procedure}\1\  \37\\{prepare\_mag};\2\6
\&{begin} \37\&{if} $(\\{mag\_set}>0)\W(\\{mag}\I\\{mag\_set})$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Incompatible\ magnification\ ("})$;\5
$\\{print\_int}(\\{mag})$;\5
$\\{print}(\.{");"})$;\5
$\\{print\_nl}(\.{"\ the\ previous\ value\ will\ be\ retained"})$;\5
$\\{help2}(\.{"I\ can\ handle\ only\ one\ magnification\ ratio\ per\ job.\ So\
I\'ve"})$\6
$(\.{"reverted\ to\ the\ magnification\ you\ used\ earlier\ on\ this\ run."})$;%
\6
$\\{int\_error}(\\{mag\_set})$;\5
$\\{geq\_word\_define}(\\{int\_base}+\\{mag\_code},\39\\{mag\_set})$;\C{$%
\\{mag}\K\\{mag\_set}$}\6
\&{end};\2\6
\&{if} $(\\{mag}\L0)\V(\\{mag}>32768)$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Illegal\ magnification\ has\ been\ changed\ to%
\ 1000"})$;\6
$\\{help1}(\.{"The\ magnification\ ratio\ must\ be\ between\ 1\ and\
32768."})$;\5
$\\{int\_error}(\\{mag})$;\5
$\\{geq\_word\_define}(\\{int\_base}+\\{mag\_code},\391000)$;\6
\&{end};\2\6
$\\{mag\_set}\K\\{mag}$;\6
\&{end};\par
\fi

\N289.  \[20] Token lists.
A \TeX\ token is either a character or a control sequence, and it is
represented internally in one of two ways: (1)~A character whose ASCII
code number is \|c and whose command code is \|m is represented as the
number $2↑8m+c$; the command code is in the range $1\L\|m\L14$. (2)~A control
sequence whose \\{eqtb} address is \|p is represented as the number
$\\{cs\_token\_flag}+\|p$. Here $\\{cs\_token\_flag}=\hbox{$2↑{12}$}$ is larger
than
$2↑8m+c$, yet it is small enough that $\\{cs\_token\_flag}+\|p<\\{max%
\_halfword}$;
thus, a token fits comfortably in a halfword.

A token \|t represents a \\{left\_brace} command if and only if
$\|t<\\{left\_brace\_limit}$; it represents a \\{right\_brace} command if and
only if
we have $\\{left\_brace\_limit}\L\|t<\\{right\_brace\_limit}$; and it
represents a \\{match} or
\\{end\_match} command if and only if $\\{match\_token}\L\|t\L\\{end\_match%
\_token}$.
The following definitions take care of these token-oriented constants
and a few others.

\Y\P\D \37$\\{cs\_token\_flag}\S\O{10000}$\C{amount added to the \\{eqtb}
location in a 	token that stands for a control sequence; is a multiple of~256}%
\par
\P\D \37$\\{left\_brace\_token}=\O{0400}$\C{$2↑8\cdot\\{left\_brace}$}\par
\P\D \37$\\{left\_brace\_limit}=\O{1000}$\C{$2↑8\cdot(\\{left\_brace}+1)$}\par
\P\D \37$\\{right\_brace\_token}=\O{1000}$\C{$2↑8\cdot\\{right\_brace}$}\par
\P\D \37$\\{right\_brace\_limit}=\O{1400}$\C{$2↑8\cdot(\\{right\_brace}+1)$}\par
\P\D \37$\\{math\_shift\_token}=\O{1400}$\C{$2↑8\cdot\\{math\_shift}$}\par
\P\D \37$\\{tab\_token}=\O{2000}$\C{$2↑8\cdot\\{tab\_mark}$}\par
\P\D \37$\\{out\_param\_token}=\O{2400}$\C{$2↑8\cdot\\{out\_param}$}\par
\P\D \37$\\{space\_token}=\O{5040}$\C{$2↑8\cdot\\{spacer}+\.{"\ "}$}\par
\P\D \37$\\{letter\_token}=\O{5400}$\C{$2↑8\cdot\\{letter}$}\par
\P\D \37$\\{other\_token}=\O{6000}$\C{$2↑8\cdot\\{other\_char}$}\par
\P\D \37$\\{match\_token}=\O{6400}$\C{$2↑8\cdot\\{match}$}\par
\P\D \37$\\{end\_match\_token}=\O{7000}$\C{$2↑8\cdot\\{end\_match}$}\par
\fi

\M290. \P$\X14:Check the ``constant'' values for consistency\X\mathrel{+}\S$\6
\&{if} $\\{cs\_token\_flag}+\\{undefined\_control\_sequence}>\\{max\_halfword}$
\1\&{then}\5
$\\{bad}\K21$;\2\par
\fi

\M291. A token list is a singly linked list of one-word nodes in \\{mem}, where
each word contains a token and a link. Macro definitions, output-routine
definitions, marks, and \.{\\write} texts are kept in \TeX's memory in the
form of token lists, preceded by a node that has a reference count in its
\\{token\_ref\_count} field. The token stored in location \|p is called
$\\{info}(\|p)$.

Three special commands appear in the token lists of macro definitions.
When $\|m=\\{match}$, it means that \TeX\ should scan a parameter
for the current macro; when $\|m=\\{end\_match}$, it means that parameter
matching should end and \TeX\ should start reading the macro text; and
when $\|m=\\{out\_param}$, it means that \TeX\ should insert parameter
number \|c into the text at this point.

The enclosing \.{\char'173} and \.{\char'175} characters of a macro
definition are omitted, but the final right brace of an output routine
is included at the end of its token list.

Here is an example macro definition that illustrates these conventions.
After \TeX\ processes the text
$$\.{\\def\\mac a\#1\#2 \\b \{\#1\\-a \#\#1\#2 \#2\}}$$
the definition of \.{\\mac} is represented as a token list containing
$$\def\,{\hskip2pt}
\vbox{\halign{\hfil#\hfil\cr
(reference count), \\{letter}\,\.a, \\{match}\,\#, \\{match}\,\#, \\{spacer}\,%
\.\ ,
\.{\\b}, \\{end\_match},\cr
\\{out\_param}\,1, \.{\\-}, \\{letter}\,\.a, \\{spacer}\,\.\ , \\{mac\_param}\,%
\#,
\\{other\_char}\,\.1,\cr
\\{out\_param}\,2, \\{spacer}\,\.\ , \\{out\_param}\,2.\cr}}$$
The procedure \\{scan\_toks} builds such token lists, and \\{macro\_call}
does the parameter matching.

Examples such as
$$\.{\\def\\m\{\\def\\m\{a\}\ b\}}$$
explain why reference counts would be needed even if \TeX\ had no \.{\\let}
operation: When the token list for \.{\\m} is being read, the redefinition of
\.{\\m} changes the \\{eqtb} entry before the token list has been fully
consumed, so we dare not simply destroy a token list when its
control sequence is being redefined.

If the parameter-matching part of a definition ends with `\.{\#\{}',
the corresponding token list will have `\.\{' just before the `\\{end\_match}'
and also at the very end. The first `\.\{' is used to delimit the parameter;
the
second one keeps the first from disappearing.

\fi

\M292. The procedure \\{show\_token\_list}, which prints a symbolic form of
the token list that starts at a given node \|p, illustrates these
conventions. The token list being displayed should not begin with a reference
count. However, the procedure is intended to be robust, so that if the
memory links are awry or if \|p is not really a pointer to a token list,
nothing catastrophic will happen.

An additional parameter \|q is also given; this parameter is either null
or it points to a node in the token list where a certain magic computation
takes place that will be explained later. (Basically, \|q is non-null when
we are printing the two-line context information at the time of an error
message; \|q marks the place corresponding to where the second line
should begin.)

For example, if \|p points to the node containing the first \.a in the
token list above, then \\{show\_token\_list} will print the string
$$\hbox{`\.{a\#1\#2\ \\b\ ->\#1\\-a\ \#\#1\#2\ \#2}';}$$
and if \|q points to the node containing the second \.a,
the magic computation will be performed just before the second \.a is printed.

The generation will stop, and `\.{\\ETC.}' will be printed, if the length
of printing exceeds a given limit~\|l. Anomalous entries are printed in the
form of control sequences that are not followed by a blank space, e.g.,
`\.{\\BAD.}'; this cannot be confused with actual control sequences because
a real control sequence named \.{BAD} would come out `\.{\\BAD\ }'.

\Y\P$\4\X292:Declare the procedure called \\{show\_token\_list}\X\S$\6
\4\&{procedure}\1\  \37$\\{show\_token\_list}(\|p,\39\|q:\\{integer};\,\35\|l:%
\\{integer})$;\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37$\|m,\39\|c$: \37\\{integer};\C{pieces of a token}\6
\\{match\_chr}: \37\\{ASCII\_code};\C{character used in a `\\{match}'}\6
\|n: \37\\{ASCII\_code};\C{the highest parameter number, as an ASCII digit}\2\6
\&{begin} \37$\\{match\_chr}\K\.{"\#"}$;\5
$\|n\K\.{"0"}$;\5
$\\{tally}\K0$;\6
\&{while} $(\|p\I\\{null})\W(\\{tally}<\|l)$ \1\&{do}\6
\&{begin} \37\&{if} $\|p=\|q$ \1\&{then}\5
\X320:Do magic computation\X;\2\6
\X293:Display token \|p, and \&{return} if there are problems\X;\6
$\|p\K\\{link}(\|p)$;\6
\&{end};\2\6
\&{if} $\|p\I\\{null}$ \1\&{then}\5
$\\{print\_esc}(\.{"ETC."})$;\2\6
\4\\{exit}: \37\&{end};\par
\U section~119.\fi

\M293. \P$\X293:Display token \|p, and \&{return} if there are problems\X\S$\6
\&{if} $(\|p<\\{hi\_mem\_min})\V(\|p>\\{mem\_end})$ \1\&{then}\6
\&{begin} \37$\\{print\_esc}(\.{"CLOBBERED."})$;\5
\&{return};\6
\&{end};\2\6
\&{if} $\\{info}(\|p)\G\\{cs\_token\_flag}$ \1\&{then}\5
$\\{print\_cs}(\\{info}(\|p)-\\{cs\_token\_flag})$\6
\4\&{else} \&{begin} \37$\|m\K\\{info}(\|p)\mathbin{\&{div}}\O{400}$;\5
$\|c\K\\{info}(\|p)\mathbin{\&{mod}}\O{400}$;\6
\&{if} $(\\{info}(\|p)<0)\V(\|c>127)$ \1\&{then}\5
$\\{print\_esc}(\.{"BAD."})$\6
\4\&{else} \X294:Display the token $(\|m,\|c)$\X;\2\6
\&{end}\2\par
\U section~292.\fi

\M294. The procedure usually ``learns'' the character code used for macro
parameters by seeing one in a \\{match} command before it runs into any
\\{out\_param} commands.

\Y\P$\4\X294:Display the token $(\|m,\|c)$\X\S$\6
\&{case} $\|m$ \1\&{of}\6
\4$\\{left\_brace},\39\\{right\_brace},\39\\{math\_shift},\39\\{tab\_mark},\39%
\\{sup\_mark},\39\\{sub\_mark},\39\\{spacer},\39\\{letter},\39\\{other\_char}$:
\37$\\{print}(\|c)$;\6
\4\\{mac\_param}: \37\&{begin} \37$\\{print}(\|c)$;\5
$\\{print}(\|c)$;\6
\&{end};\6
\4\\{out\_param}: \37\&{begin} \37$\\{print}(\\{match\_chr})$;\6
\&{if} $\|c\L9$ \1\&{then}\5
$\\{print\_char}(\|c+\.{"0"})$\6
\4\&{else} \&{begin} \37$\\{print\_char}(\.{"!"})$;\5
\&{return};\6
\&{end};\2\6
\&{end};\6
\4\\{match}: \37\&{begin} \37$\\{match\_chr}\K\|c$;\5
$\\{print}(\|c)$;\5
$\\{incr}(\|n)$;\5
$\\{print\_char}(\|n)$;\6
\&{if} $\|n>\.{"9"}$ \1\&{then}\5
\&{return};\2\6
\&{end};\6
\4\\{end\_match}: \37$\\{print}(\.{"->"})$;\6
\4\&{othercases} \37$\\{print\_esc}(\.{"BAD."})$\2\6
\&{endcases}\par
\U section~293.\fi

\M295. Here's the way we sometimes want to display a token list, given a
pointer
to its reference count; the pointer may be null.

\Y\P\4\&{procedure}\1\  \37$\\{token\_show}(\|p:\\{pointer})$;\2\6
\&{begin} \37\&{if} $\|p\I\\{null}$ \1\&{then}\5
$\\{show\_token\_list}(\\{link}(\|p),\39\\{null},\391000)$;\2\6
\&{end};\par
\fi

\M296. The \\{print\_meaning} subroutine displays \\{cur\_cmd} and \\{cur\_chr}
in
symbolic form, including the expansion of a macro or mark.

\Y\P\4\&{procedure}\1\  \37\\{print\_meaning};\2\6
\&{begin} \37$\\{print\_cmd\_chr}(\\{cur\_cmd},\39\\{cur\_chr})$;\6
\&{if} $\\{cur\_cmd}\G\\{call}$ \1\&{then}\6
\&{begin} \37$\\{print\_char}(\.{":"})$;\5
\\{print\_ln};\5
$\\{token\_show}(\\{cur\_chr})$;\6
\&{end}\6
\4\&{else} \&{if} $\\{cur\_cmd}=\\{top\_bot\_mark}$ \1\&{then}\6
\&{begin} \37$\\{print\_char}(\.{":"})$;\5
\\{print\_ln};\5
$\\{token\_show}(\\{cur\_mark}[\\{cur\_chr}])$;\6
\&{end};\2\2\6
\&{end};\par
\fi

\N297.  \[21] Introduction to the syntactic routines.
Let's pause a moment now and try to look at the Big Picture.
The \TeX\ program consists of three main parts: syntactic routines,
semantic routines, and output routines. The chief purpose of the
syntactic routines is to deliver the user's input to the semantic routines,
one token at a time. The semantic routines act as an interpreter
responding to these tokens, which may be regarded as commands. And the
output routines are periodically called on to convert box-and-glue
lists into a compact set of instructions that will be sent
to a typesetter. We have discussed the basic data structures and utility
routines of \TeX, so we are good and ready to plunge into the real activity by
considering the syntactic routines.

Our current goal is to come to grips with the \\{get\_next} procedure,
which is the keystone of \TeX's input mechanism. Each call of \\{get\_next}
sets the value of three variables \\{cur\_cmd}, \\{cur\_chr}, and \\{cur\_cs},
representing the next input token.
$$\vbox{\halign{#\hfil\cr
\hbox{\\{cur\_cmd} denotes a command code from the long list of codes
given above;}\cr
\hbox{\\{cur\_chr} denotes a character code or other modifier of the command
code;}\cr
\hbox{\\{cur\_cs} is the \\{eqtb} location of the current control sequence,}\cr
\hbox{\qquad if the current token was a control sequence,
otherwise it's zero.}\cr}}$$
Underlying this external behavior of \\{get\_next} is all the machinery
necessary to convert from character files to tokens. At a given time we
may be only partially finished with the reading of several files (for
which \.{\\input} was specified), and partially finished with the expansion
of some user-defined macros and/or some macro parameters, and partially
finished with the generation of some text in a template for \.{\\halign},
and so on. When reading a character file, special characters must be
classified as math delimiters, etc.; comments and extra blank spaces must
be removed, paragraphs must be recognized, and control sequences must be
found in the hash table. Furthermore there are occasions in which the
scanning routines have looked ahead for a word like `\.{plus}' but only
part of that word was found, hence a few characters must be put back
into the input and scanned again.

To handle these situations, which might all be present simultaneously,
\TeX\ uses various stacks that hold information about the incomplete
activities, and there is a finite state control for each level of the
input mechanism. These stacks record the current state of an implicitly
recursive process, but the \\{get\_next} procedure is not recursive.
Therefore it will not be difficult to translate these algorithms into
low-level languages that do not support recursion.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{cur\_cmd}: \37\\{eight\_bits};\C{current command set by \\{get\_next}}\6
\4\\{cur\_chr}: \37\\{halfword};\C{operand of current command}\6
\4\\{cur\_cs}: \37\\{pointer};\C{control sequence found here, zero if none
found}\6
\4\\{cur\_tok}: \37\\{halfword};\C{packed representative of \\{cur\_cmd} and %
\\{cur\_chr}}\par
\fi

\M298. The \\{print\_cmd\_chr} routine prints a symbolic interpretation of a
command code and its modifier. This is used in certain `\.{You can\'t}'
error messages, and in the implementation of diagnostic routines like
\.{\\show}.

The body of \\{print\_cmd\_chr} is a rather tedious listing of print
commands, and most of it is essentially an inverse to the \\{primitive}
routine that enters a \TeX\ primitive into \\{eqtb}. Therefore much of
this procedure appears elsewhere in the program,
together with the corresponding \\{primitive} calls.

\Y\P\D \37$\\{chr\_cmd}(\#)\S$\1\6
\&{begin} \37$\\{print}(\#)$;\5
$\\{print\_ASCII}(\\{chr\_code})$;\6
\&{end}\2\par
\Y\P$\4\X298:Declare the procedure called \\{print\_cmd\_chr}\X\S$\6
\4\&{procedure}\1\  \37$\\{print\_cmd\_chr}(\\{cmd}:\\{quarterword};\,\35\\{chr%
\_code}:\\{halfword})$;\2\6
\&{begin} \37\&{case} $\\{cmd}$ \1\&{of}\6
\4\\{left\_brace}: \37$\\{chr\_cmd}(\.{"begin-group\ character\ "})$;\6
\4\\{right\_brace}: \37$\\{chr\_cmd}(\.{"end-group\ character\ "})$;\6
\4\\{math\_shift}: \37$\\{chr\_cmd}(\.{"math\ shift\ character\ "})$;\6
\4\\{mac\_param}: \37$\\{chr\_cmd}(\.{"macro\ parameter\ character\ "})$;\6
\4\\{sup\_mark}: \37$\\{chr\_cmd}(\.{"superscript\ character\ "})$;\6
\4\\{sub\_mark}: \37$\\{chr\_cmd}(\.{"subscript\ character\ "})$;\6
\4\\{endv}: \37$\\{print}(\.{"end\ of\ alignment\ template"})$;\6
\4\\{spacer}: \37$\\{chr\_cmd}(\.{"blank\ space\ "})$;\6
\4\\{letter}: \37$\\{chr\_cmd}(\.{"the\ letter\ "})$;\6
\4\\{other\_char}: \37$\\{chr\_cmd}(\.{"the\ character\ "})$;\6
\hbox{\4}\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of primitives%
\X\6
\4\&{othercases} \37$\\{print}(\.{"[unknown\ command\ code!]"})$\2\6
\&{endcases};\6
\&{end};\par
\U section~252.\fi

\M299. Here is a procedure that displays the current command.

\Y\P\4\&{procedure}\1\  \37\\{show\_cur\_cmd\_chr};\2\6
\&{begin} \37\\{begin\_diagnostic};\5
$\\{print\_nl}(\.{"\{"})$;\6
\&{if} $\\{mode}\I\\{shown\_mode}$ \1\&{then}\6
\&{begin} \37$\\{print\_mode}(\\{mode})$;\5
$\\{print}(\.{":\ "})$;\5
$\\{shown\_mode}\K\\{mode}$;\6
\&{end};\2\6
$\\{print\_cmd\_chr}(\\{cur\_cmd},\39\\{cur\_chr})$;\5
$\\{print\_char}(\.{"\}"})$;\5
$\\{end\_diagnostic}(\\{false})$;\6
\&{end};\par
\fi

\N300.  \[22] Input stacks and states.
\TeX\ uses two different conventions for representing sequential stacks.

\yskip\hang 1) If there is frequent access to the top entry, and if the
stack is essentially never empty, then the top entry is kept in a global
variable (even better would be a machine register), and the other entries
appear in the array $\\{stack}[0\to(\\{ptr}-1)]$. For example, the
semantic stack described above is handled this way, and so is the input
stack that we are about to study.

\yskip\hang 2) If there is infrequent top access, the entire stack contents
are in the array $\\{stack}[0\to(\\{ptr}-1)]$. For example, the \\{save\_stack}
is treated this way, as we have seen.

\yskip\noindent
The state of \TeX's input mechanism appears in the input stack, whose
entries are records with six fields, called \\{state}, \\{index}, \\{start}, %
\\{loc},
\\{limit}, and \\{name}. This stack is maintained with
convention~(1), so it is declared in the following way:

\Y\P$\4\X18:Types in the outer block\X\mathrel{+}\S$\6
$\\{in\_state\_record}=$\1\5
\1\&{record} \37$\\{state\_field},\39\\{index\_field}$: \37\\{quarterword};\6
\4$\\{start\_field},\39\\{loc\_field},\39\\{limit\_field},\39\\{name\_field}$: %
\37\\{halfword};\2\6
\&{end};\2\par
\fi

\M301. \P$\X13:Global variables\X\mathrel{+}\S$\6
\4\\{input\_stack}: \37\&{array} $[0\to\\{stack\_size}]$ \1\&{of}\5
\\{in\_state\_record};\2\6
\4\\{input\_ptr}: \37$0\to\\{stack\_size}$;\C{first unused location of \\{input%
\_stack}}\6
\4\\{max\_in\_stack}: \37$0\to\\{stack\_size}$;\C{largest value of \\{input%
\_ptr} when pushing}\6
\4\\{cur\_input}: \37\\{in\_state\_record};\C{the ``top'' input state,
according to convention (1)}\par
\fi

\M302. We've already defined the special variable $\\{loc}\S\\{cur\_input}.%
\\{loc\_field}$
in our discussion of basic input-output routines. The other components of
\\{cur\_input} are defined in the same way:

\Y\P\D \37$\\{state}\S\\{cur\_input}.\\{state\_field}$\C{current scanner state}%
\par
\P\D \37$\\{index}\S\\{cur\_input}.\\{index\_field}$\C{reference for buffer
information}\par
\P\D \37$\\{start}\S\\{cur\_input}.\\{start\_field}$\C{starting position in %
\\{buffer}}\par
\P\D \37$\\{limit}\S\\{cur\_input}.\\{limit\_field}$\C{end of current line in %
\\{buffer}}\par
\P\D \37$\\{name}\S\\{cur\_input}.\\{name\_field}$\C{name of the current file}%
\par
\fi

\M303. Let's look more closely now at the six control variables
(\\{state},~\\{index},~\\{start},~\\{loc},~\\{limit},~\\{name}),
assuming that \TeX\ is reading a line of characters that have been input
from some file or from the user's terminal. There is an array called
\\{buffer} that acts as a stack of all lines of characters that are
currently being read from files, including all lines on subsidiary
levels of the input stack that are not yet completed. We will return to
the other lines when we are finished with the present input file.

(Incidentally, on a machine with byte-oriented addressing, it would be
appropriate to combine \\{buffer} with the \\{str\_pool} array,
letting the buffer entries grow downward from the top of the string pool
and checking that these two tables don't bump into each other.)

The line we are currently working on begins in position \\{start} of the
buffer; the next character we are about to read is $\\{buffer}[\\{loc}]$; and
\\{limit} is the location of the last character present.  If $\\{loc}>%
\\{limit}$,
the line has been completely read. Usually $\\{buffer}[\\{limit}]$ is the
\\{end\_line\_char}, denoting the end of a line, but this is not
true if the current line is an insertion that was entered on the user's
terminal in response to an error message.

The \\{name} variable is a string number that designates the name of
the current file, if we are reading a text file. It is zero if we
are reading from the terminal; it is $\|n+1$ if we are reading from
input stream \|n, where $0\L\|n\L16$. (Input stream 16 stands for
an invalid stream number; in such cases the input is actually from
the terminal, under control of the procedure \\{read\_toks}.)

The \\{state} variable has one of three values, when we are scanning such
files:
$$\baselineskip 15pt\vbox{\halign{#\hfil\cr
1) $\\{state}=\\{mid\_line}$ is the normal state.\cr
2) $\\{state}=\\{skip\_blanks}$ is like \\{mid\_line}, but blanks are ignored.%
\cr
3) $\\{state}=\\{new\_line}$ is the state at the beginning of a line.\cr}}$$
These state values are assigned numeric codes so that if we add the state
code to the next character's command code, we get distinct values. For
example, `$\\{mid\_line}+\\{spacer}$' stands for the case that a blank
space character occurs in the middle of a line when it is not being
ignored; after this case is processed, the next value of \\{state} will
be \\{skip\_blanks}.

\Y\P\D \37$\\{mid\_line}=1$\C{\\{state} code when scanning a line of
characters}\par
\P\D \37$\\{skip\_blanks}=2+\\{max\_char\_code}$\C{\\{state} code when ignoring
blanks}\par
\P\D \37$\\{new\_line}=3+\\{max\_char\_code}+\\{max\_char\_code}$\C{\\{state}
code at start of line}\par
\fi

\M304\*. Additional information about the current line is available via the
\\{index} variable, which counts how many lines of characters are present
in the buffer below the current level. We have $\\{index}=0$ when reading
from the terminal and prompting the user for each line; then if the user types,
e.g., `\.{\\input paper}', we will have $\\{index}=1$ while reading
the file \.{paper.tex}. However, it does not follow that \\{index} is the
same as the input stack pointer, since many of the levels on the input
stack may come from token lists. For example, the instruction `\.{\\input
paper}' might occur in a token list.

The global variable \\{in\_open} is equal to the \\{index}
value of the highest non-token-list level. Thus, the number of partially read
lines in the buffer is $\\{in\_open}+1$, and we have $\\{in\_open}=\\{index}$
when we are not reading a token list.

If we are not currently reading from the terminal, or from an input
stream, we are reading from the file variable $\\{input\_file}[\\{index}]$. We
use
the notation \\{terminal\_input} as a convenient abbreviation for $\\{name}=0$,
and \\{cur\_file} as an abbreviation for $\\{input\_file}[\\{index}]$.

The global variable \\{line} contains the line number in the topmost
open file, for use in error messages. If we are not reading from
the terminal, $\\{line\_stack}[\\{index}]$ holds the line number for the
enclosing level, so that \\{line} can be restored when the current
file has been read. Line numbers should never be negative, since the
negative of the current line number is used to identify the user's output
routine in the \\{mode\_line} field of the semantic nest entries.

Similarly, we maintain a global variable \\{page} and a corresponding
\\{page\_stack}.

\Y\P\D \37$\\{terminal\_input}\S(\\{name}=0)$\C{are we reading from the
terminal?}\par
\P\D \37$\\{cur\_file}\S\\{input\_file}[\\{index}]$\C{the current \\{alpha%
\_file} variable}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{in\_open}: \37$0\to\\{max\_in\_open}$;\C{the number of lines in the
buffer, less one}\6
\4\\{input\_file}: \37\&{array} $[1\to\\{max\_in\_open}]$ \1\&{of}\5
\\{alpha\_file};\2\6
\4\\{line}: \37\\{integer};\C{current line number in the current source file}\6
\4\\{line\_stack}: \37\&{array} $[1\to\\{max\_in\_open}]$ \1\&{of}\5
\\{integer};\2\6
\4\\{page}: \37\\{integer};\C{current page number in the current source file}\6
\4\\{page\_stack}: \37\&{array} $[1\to\\{max\_in\_open}]$ \1\&{of}\5
\\{integer};\2\par
\fi

\M305. Users of \TeX\ sometimes forget to balance left and right braces
properly,
and one of the ways \TeX\ tries to spot such errors is by considering an
input file as broken into subfiles by control sequences that
are declared to be \.{\\outer}.

A variable called \\{scanner\_status} tells \TeX\ whether or not to complain
when a subfile ends. This variable has six possible values:

\yskip\hang\\{normal}, means that a subfile can safely end here without
incident.

\yskip\hang\\{skipping}, means that a subfile can safely end here, but not a
file,
because we're reading past some conditional text that was not selected.

\yskip\hang\\{defining}, means that a subfile shouldn't end now because a
macro is being defined.

\yskip\hang\\{matching}, means that a subfile shouldn't end now because a
macro is being used and we are searching for the end of its arguments.

\yskip\hang\\{aligning}, means that a subfile shouldn't end now because we are
not finished with the preamble of an \.{\\halign} or \.{\\valign}.

\yskip\hang\\{absorbing}, means that a subfile shouldn't end now because we are
reading a balanced token list for \.{\\message}, \.{\\write}, etc.

\yskip\noindent
If the \\{scanner\_status} is not \\{normal}, the variable \\{warning\_index}
points
to the \\{eqtb} location for the relevant control sequence name to print
in an error message.

\Y\P\D \37$\\{skipping}=1$\C{\\{scanner\_status} when passing conditional text}%
\par
\P\D \37$\\{defining}=2$\C{\\{scanner\_status} when reading a macro definition}%
\par
\P\D \37$\\{matching}=3$\C{\\{scanner\_status} when reading macro arguments}\par
\P\D \37$\\{aligning}=4$\C{\\{scanner\_status} when reading an alignment
preamble}\par
\P\D \37$\\{absorbing}=5$\C{\\{scanner\_status} when reading a balanced text}%
\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{scanner\_status}: \37$\\{normal}\to\\{absorbing}$;\C{can a subfile end
now?}\6
\4\\{warning\_index}: \37\\{pointer};\C{identifier relevant to non-\\{normal}
scanner status}\6
\4\\{def\_ref}: \37\\{pointer};\C{reference count of token list being defined}%
\par
\fi

\M306. Here is a procedure that uses \\{scanner\_status} to print a warning
message
when a subfile has ended, and at certain other crucial times:

\Y\P$\4\X306:Declare the procedure called \\{runaway}\X\S$\6
\4\&{procedure}\1\  \37\\{runaway};\6
\4\&{var} \37\|p: \37\\{pointer};\C{head of runaway list}\2\6
\&{begin} \37\&{if} $\\{scanner\_status}>\\{skipping}$ \1\&{then}\6
\&{begin} \37$\\{print\_nl}(\.{"Runaway\ "})$;\6
\&{case} $\\{scanner\_status}$ \1\&{of}\6
\4\\{defining}: \37\&{begin} \37$\\{print}(\.{"definition"})$;\5
$\|p\K\\{def\_ref}$;\6
\&{end};\6
\4\\{matching}: \37\&{begin} \37$\\{print}(\.{"argument"})$;\5
$\|p\K\\{temp\_head}$;\6
\&{end};\6
\4\\{aligning}: \37\&{begin} \37$\\{print}(\.{"preamble"})$;\5
$\|p\K\\{hold\_head}$;\6
\&{end};\6
\4\\{absorbing}: \37\&{begin} \37$\\{print}(\.{"text"})$;\5
$\|p\K\\{def\_ref}$;\6
\&{end};\2\6
\&{end};\C{there are no other cases}\6
$\\{print\_char}(\.{"?"})$;\5
\\{print\_ln};\5
$\\{show\_token\_list}(\\{link}(\|p),\39\\{null},\39\\{error\_line}-10)$;\6
\&{end};\2\6
\&{end};\par
\U section~119.\fi

\M307. However, all this discussion about input state really applies only to
the
case that we are inputting from a file. There is another important case,
namely when we are currently getting input from a token list. In this case
$\\{state}=\\{token\_list}$, and the conventions about the other state
variables
are different:

\yskip\hang\\{loc} is a pointer to the current node in the token list, i.e.,
the node that will be read next. If $\\{loc}=\\{null}$, the token list has been
fully read.

\yskip\hang\\{start} points to the first node of the token list; this node
may or may not contain a reference count, depending on the type of token
list involved.

\yskip\hang\\{token\_type}, which takes the place of \\{index} in the
discussion above, is a code number that explains what kind of token list
is being scanned.

\yskip\hang\\{name} points to the \\{eqtb} address of the control sequence
being expanded, if the current token list is a macro.

\yskip\hang\\{param\_start}, which takes the place of \\{limit}, tells where
the parameters of the current macro begin in the \\{param\_stack}, if the
current token list is a macro.

\yskip\noindent The \\{token\_type} can take several values, depending on
where the current token list came from:

\yskip\hang\\{parameter}, if a parameter is being scanned;

\hang\\{u\_template}, if the \<u_j> part of an alignment
template is being scanned;

\hang\\{v\_template}, if the \<v_j> part of an alignment
template is being scanned;

\hang\\{backed\_up}, if the token list being scanned has been inserted as
`to be read again'.

\hang\\{inserted}, if the token list being scanned has been inserted as
the text expansion of a \.{\\count} or similar variable;

\hang\\{macro}, if a user-defined control sequence is being scanned;

\hang\\{output\_text}, if an \.{\\output} routine is being scanned;

\hang\\{every\_par\_text}, if the text of \.{\\everypar} is being scanned;

\hang\\{every\_math\_text}, if the text of \.{\\everymath} is being scanned;

\hang\\{every\_display\_text}, if the text of \.{\\everydisplay} is being
scanned;

\hang\\{every\_hbox\_text}, if the text of \.{\\everyhbox} is being scanned;

\hang\\{every\_vbox\_text}, if the text of \.{\\everyvbox} is being scanned;

\hang\\{every\_job\_text}, if the text of \.{\\everyjob} is being scanned;

\hang\\{every\_cr\_text}, if the text of \.{\\everycr} is being scanned;

\hang\\{mark\_text}, if the text of a \.{\\mark} is being scanned;

\hang\\{write\_text}, if the text of a \.{\\write} is being scanned.

\yskip\noindent
The codes for \\{output\_text}, \\{every\_par\_text}, etc., are equal to a
constant
plus the corresponding codes for token list parameters \\{output\_routine%
\_loc},
\\{every\_par\_loc}, etc.  The token list begins with a reference count if and
only if $\\{token\_type}\G\\{macro}$.

\Y\P\D \37$\\{token\_list}=0$\C{\\{state} code when scanning a token list}\par
\P\D \37$\\{token\_type}\S\\{index}$\C{type of current token list}\par
\P\D \37$\\{param\_start}\S\\{limit}$\C{base of macro parameters in \\{param%
\_stack}}\par
\P\D \37$\\{parameter}=0$\C{\\{token\_type} code for parameter}\par
\P\D \37$\\{u\_template}=1$\C{\\{token\_type} code for \<u_j> template}\par
\P\D \37$\\{v\_template}=2$\C{\\{token\_type} code for \<v_j> template}\par
\P\D \37$\\{backed\_up}=3$\C{\\{token\_type} code for text to be reread}\par
\P\D \37$\\{inserted}=4$\C{\\{token\_type} code for inserted texts}\par
\P\D \37$\\{macro}=5$\C{\\{token\_type} code for defined control sequences}\par
\P\D \37$\\{output\_text}=6$\C{\\{token\_type} code for output routines}\par
\P\D \37$\\{every\_par\_text}=7$\C{\\{token\_type} code for \.{\\everypar}}\par
\P\D \37$\\{every\_math\_text}=8$\C{\\{token\_type} code for \.{\\everymath}}%
\par
\P\D \37$\\{every\_display\_text}=9$\C{\\{token\_type} code for \.{%
\\everydisplay}}\par
\P\D \37$\\{every\_hbox\_text}=10$\C{\\{token\_type} code for \.{\\everyhbox}}%
\par
\P\D \37$\\{every\_vbox\_text}=11$\C{\\{token\_type} code for \.{\\everyvbox}}%
\par
\P\D \37$\\{every\_job\_text}=12$\C{\\{token\_type} code for \.{\\everyjob}}\par
\P\D \37$\\{every\_cr\_text}=13$\C{\\{token\_type} code for \.{\\everycr}}\par
\P\D \37$\\{mark\_text}=14$\C{\\{token\_type} code for \.{\\topmark}, etc.}\par
\P\D \37$\\{write\_text}=15$\C{\\{token\_type} code for \.{\\write}}\par
\fi

\M308. The \\{param\_stack} is an auxiliary array used to hold pointers to the
token
lists for parameters at the current level and subsidiary levels of input.
This stack is maintained with convention (2), and it grows at a different
rate from the others.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{param\_stack}: \37\&{array} $[0\to\\{param\_size}]$ \1\&{of}\5
\\{pointer};\C{token list pointers for parameters}\2\6
\4\\{param\_ptr}: \37$0\to\\{param\_size}$;\C{first unused entry in \\{param%
\_stack}}\6
\4\\{max\_param\_stack}: \37\\{integer};\C{largest value of \\{param\_ptr},
will be $\L\\{param\_size}+9$}\par
\fi

\M309. The input routines must also interact with the processing of
\.{\\halign} and \.{\\valign}, since the appearance of tab marks and
\.{\\cr} in certain places is supposed to trigger the beginning of special
\<v_j> template text in the scanner. This magic is accomplished by an
\\{align\_state} variable that is increased by~1 when a `\.{\char'173}' is
scanned and decreased by~1 when a `\.{\char'175}' is scanned. The \\{align%
\_state}
is nonzero during the \<u_j> template, after which it is set to zero; the
\<v_j> template begins when a tab mark or \.{\\cr} occurs at a time that
$\\{align\_state}=0$.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{align\_state}: \37\\{integer};\C{group level with respect to current
alignment}\par
\fi

\M310. Thus, the ``current input state'' can be very complicated indeed; there
can be many levels and each level can arise in a variety of ways. The
\\{show\_context} procedure, which is used by \TeX's error-reporting routine to
print out the current input state on all levels down to the most recent
line of characters from an input file, illustrates most of these conventions.
The global variable \\{base\_ptr} contains the lowest level that was
displayed by this procedure.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{base\_ptr}: \37$0\to\\{stack\_size}$;\C{shallowest level shown by \\{show%
\_context}}\par
\fi

\M311. The status at each level is indicated by printing two lines, where the
first
line indicates what was read so far and the second line shows what remains
to be read. The context is cropped, if necessary, so that the first line
contains at most \\{half\_error\_line} characters, and the second contains
at most \\{error\_line}. Non-current input levels whose \\{token\_type} is
`\\{backed\_up}' are shown only if they have not been fully read.

\Y\P\4\&{procedure}\1\  \37\\{show\_context};\C{prints where the scanner is}\6
\4\&{label} \37\\{done};\6
\4\&{var} \37\\{old\_setting}: \37$0\to\\{max\_selector}$;\C{saved \\{selector}
setting}\6
\X315:Local variables for formatting calculations\X\2\6
\&{begin} \37$\\{base\_ptr}\K\\{input\_ptr}$;\5
$\\{input\_stack}[\\{base\_ptr}]\K\\{cur\_input}$;\C{store current state}\6
\~ \1\&{loop}\ \&{begin} \37$\\{cur\_input}\K\\{input\_stack}[\\{base\_ptr}]$;%
\C{enter into the context}\6
\X312:Display the current context\X;\6
\&{if} $(\\{state}\I\\{token\_list})$ \1\&{then}\6
\&{if} $(\\{name}>17)\V(\\{base\_ptr}=0)$ \1\&{then}\5
\&{goto} \37\\{done};\2\2\6
$\\{decr}(\\{base\_ptr})$;\6
\&{end};\2\6
\4\\{done}: \37$\\{cur\_input}\K\\{input\_stack}[\\{input\_ptr}]$;\C{restore
original state}\6
\&{end};\par
\fi

\M312. \P$\X312:Display the current context\X\S$\6
\&{if} $(\\{base\_ptr}=\\{input\_ptr})\V(\\{state}\I\\{token\_list})\V(\\{token%
\_type}\I\\{backed\_up})\V(\\{loc}\I\\{null})$ \1\&{then}\C{we omit backed-up
token lists that have already been read}\6
\&{begin} \37$\\{tally}\K0$;\C{get ready to count characters}\6
$\\{old\_setting}\K\\{selector}$;\6
\&{if} $\\{state}\I\\{token\_list}$ \1\&{then}\6
\&{begin} \37\X313\*:Print location of current line\X;\6
\X318:Pseudoprint the line\X;\6
\&{end}\6
\4\&{else} \&{begin} \37\X314:Print type of token list\X;\6
\X319:Pseudoprint the token list\X;\6
\&{end};\2\6
$\\{selector}\K\\{old\_setting}$;\C{stop pseudoprinting}\6
\X317:Print two lines using the tricky pseudoprinted information\X;\6
\&{end}\2\par
\U section~311.\fi

\M313\*. This routine should be changed, if necessary, to give the best
possible
indication of where the current line resides in the input file.
For example, on some systems it is best to print both a page and line number.

\Y\P$\4\X313\*:Print location of current line\X\S$\6
\&{if} $\\{name}\L17$ \1\&{then}\6
\&{if} $\\{terminal\_input}$ \1\&{then}\6
\&{if} $\\{base\_ptr}=0$ \1\&{then}\5
$\\{print\_nl}(\.{"<*>"})$\6
\4\&{else} $\\{print\_nl}(\.{"<insert>\ "})$\2\6
\4\&{else} \&{begin} \37$\\{print\_nl}(\.{"<read\ "})$;\6
\&{if} $\\{name}=17$ \1\&{then}\5
$\\{print\_char}(\.{"*"})$\ \&{else} $\\{print\_int}(\\{name}-1)$;\2\6
$\\{print\_char}(\.{">"})$;\6
\&{end}\2\6
\4\&{else} \&{begin} \37\&{if} $\\{page}>1$ \1\&{then}\6
\&{begin} \37$\\{print\_nl}(\.{"p."})$;\5
$\\{print\_int}(\\{page})$;\5
$\\{print}(\.{",l."})$;\6
\&{end}\6
\4\&{else} $\\{print\_nl}(\.{"l."})$;\2\6
$\\{print\_int}(\\{line})$;\6
\&{end};\2\6
$\\{print\_char}(\.{"\ "})$\par
\U section~312.\fi

\M314. \P$\X314:Print type of token list\X\S$\6
\&{case} $\\{token\_type}$ \1\&{of}\6
\4\\{parameter}: \37$\\{print\_nl}(\.{"<argument>\ "})$;\6
\4$\\{u\_template},\39\\{v\_template}$: \37$\\{print\_nl}(\.{"<template>\ "})$;%
\6
\4\\{backed\_up}: \37\&{if} $\\{loc}=\\{null}$ \1\&{then}\5
$\\{print\_nl}(\.{"<recently\ read>\ "})$\6
\4\&{else} $\\{print\_nl}(\.{"<to\ be\ read\ again>\ "})$;\2\6
\4\\{inserted}: \37$\\{print\_nl}(\.{"<inserted\ text>\ "})$;\6
\4\\{macro}: \37\&{begin} \37\\{print\_ln};\5
$\\{print\_cs}(\\{name})$;\6
\&{end};\6
\4\\{output\_text}: \37$\\{print\_nl}(\.{"<output>\ "})$;\6
\4\\{every\_par\_text}: \37$\\{print\_nl}(\.{"<everypar>\ "})$;\6
\4\\{every\_math\_text}: \37$\\{print\_nl}(\.{"<everymath>\ "})$;\6
\4\\{every\_display\_text}: \37$\\{print\_nl}(\.{"<everydisplay>\ "})$;\6
\4\\{every\_hbox\_text}: \37$\\{print\_nl}(\.{"<everyhbox>\ "})$;\6
\4\\{every\_vbox\_text}: \37$\\{print\_nl}(\.{"<everyvbox>\ "})$;\6
\4\\{every\_job\_text}: \37$\\{print\_nl}(\.{"<everyjob>\ "})$;\6
\4\\{every\_cr\_text}: \37$\\{print\_nl}(\.{"<everycr>\ "})$;\6
\4\\{mark\_text}: \37$\\{print\_nl}(\.{"<mark>\ "})$;\6
\4\\{write\_text}: \37$\\{print\_nl}(\.{"<write>\ "})$;\6
\4\&{othercases} \37$\\{print\_nl}(\.{"?"})$\C{this should never happen}\2\6
\&{endcases}\par
\U section~312.\fi

\M315. Here it is necessary to explain a little trick. We don't want to store a
long
string that corresponds to a token list, because that string might take up
lots of memory; and we are printing during a time when an error message is
being given, so we dare not do anything that might overflow one of \TeX's
tables. So `pseudoprinting' is the answer: We enter a mode of printing
that stores characters into a buffer of length \\{error\_line}, where character
$k+1$ is placed into \hbox{$\\{trick\_buf}[\|k\mathbin{\&{mod}}\\{error%
\_line}]$} if
$\|k<\\{trick\_count}$, otherwise character \|k is dropped. Initially we set
$\\{tally}\K0$ and $\\{trick\_count}\K1000000$; then when we reach the
point where transition from line 1 to line 2 should occur, we
set $\\{first\_count}\K\\{tally}$ and $\\{trick\_count}\K\hbox{max}(\\{error%
\_line},\\{tally}+1+\\{error\_line}-\\{half\_error\_line})$. At the end of the
pseudoprinting, the values of \\{first\_count}, \\{tally}, and
\\{trick\_count} give us all the information we need to print the two lines,
and all of the necessary text is in \\{trick\_buf}.

Namely, let \|l be the length of the descriptive information that appears
on the first line. The length of the context information gathered for that
line is $\|k=\\{first\_count}$, and the length of the context information
gathered for line~2 is $m=\min(\\{tally}, \\{trick\_count})-k$. If $\|l+\|k\L%
\|h$,
where $\|h=\\{half\_error\_line}$, we print $\\{trick\_buf}[0\to\|k-1]$ after
the
descriptive information on line~1, and set $\|n\K\|l+\|k$; here \|n is the
length of line~1. If $l+k>h$, some cropping is necessary, so we set $\|n\K\|h$
and print `\.{...}' followed by
$$\hbox{$\\{trick\_buf}[(\|l+\|k-\|h+3)\to\|k-1]$,}$$
where subscripts of \\{trick\_buf} are circular modulo \\{error\_line}. The
second line consists of \|n~spaces followed by $\\{trick\_buf}[\|k\to(\|k+%
\|m-1)]$,
unless $\|n+\|m>\\{error\_line}$; in the latter case, further cropping is done.
This is easier to program than to explain.

\Y\P$\4\X315:Local variables for formatting calculations\X\S$\6
\4\|i: \37$0\to\\{buf\_size}$;\C{index into \\{buffer}}\6
\4\|j: \37$0\to\\{buf\_size}$;\C{end of current line in \\{buffer}}\6
\4\|l: \37$0\to\\{half\_error\_line}$;\C{length of descriptive information on
line 1}\6
\4\|m: \37\\{integer};\C{context information gathered for line 2}\6
\4\|n: \37$0\to\\{error\_line}$;\C{length of line 1}\6
\4\|p: \37\\{integer};\C{starting or ending place in \\{trick\_buf}}\6
\4\|q: \37\\{integer};\C{temporary index}\par
\U section~311.\fi

\M316. The following code sets up the print routines so that they will gather
the desired information.

\Y\P\D \37$\\{begin\_pseudoprint}\S$\1\6
\&{begin} \37$\|l\K\\{tally}$;\5
$\\{tally}\K0$;\5
$\\{selector}\K\\{pseudo}$;\5
$\\{trick\_count}\K1000000$;\6
\&{end}\2\par
\P\D \37$\\{set\_trick\_count}\S$\1\6
\&{begin} \37$\\{first\_count}\K\\{tally}$;\5
$\\{trick\_count}\K\\{tally}+1+\\{error\_line}-\\{half\_error\_line}$;\6
\&{if} $\\{trick\_count}<\\{error\_line}$ \1\&{then}\5
$\\{trick\_count}\K\\{error\_line}$;\2\6
\&{end}\2\par
\fi

\M317. And the following code uses the information after it has been gathered.

\Y\P$\4\X317:Print two lines using the tricky pseudoprinted information\X\S$\6
\&{if} $\\{trick\_count}=1000000$ \1\&{then}\5
\\{set\_trick\_count};\C{\\{set\_trick\_count} must be performed}\2\6
\&{if} $\\{tally}<\\{trick\_count}$ \1\&{then}\5
$\|m\K\\{tally}-\\{first\_count}$\6
\4\&{else} $\|m\K\\{trick\_count}-\\{first\_count}$;\C{context on line 2}\2\6
\&{if} $\|l+\\{first\_count}\L\\{half\_error\_line}$ \1\&{then}\6
\&{begin} \37$\|p\K0$;\5
$\|n\K\|l+\\{first\_count}$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{print}(\.{"..."})$;\5
$\|p\K\|l+\\{first\_count}-\\{half\_error\_line}+3$;\5
$\|n\K\\{half\_error\_line}$;\6
\&{end};\2\6
\&{for} $\|q\K\|p\mathrel{\&{to}}\\{first\_count}-1$ \1\&{do}\5
$\\{print\_char}(\\{trick\_buf}[\|q\mathbin{\&{mod}}\\{error\_line}])$;\2\6
\\{print\_ln};\6
\&{for} $\|q\K1\mathrel{\&{to}}\|n$ \1\&{do}\5
$\\{print\_char}(\.{"\ "})$;\C{print \|n spaces to begin line~2}\2\6
\&{if} $\|m+\|n\L\\{error\_line}$ \1\&{then}\5
$\|p\K\\{first\_count}+\|m$\6
\4\&{else} $\|p\K\\{first\_count}+(\\{error\_line}-\|n-3)$;\2\6
\&{for} $\|q\K\\{first\_count}\mathrel{\&{to}}\|p-1$ \1\&{do}\5
$\\{print\_char}(\\{trick\_buf}[\|q\mathbin{\&{mod}}\\{error\_line}])$;\2\6
\&{if} $\|m+\|n>\\{error\_line}$ \1\&{then}\5
$\\{print}(\.{"..."})$\2\par
\U section~312.\fi

\M318. But the trick is distracting us from our current goal, which is to
understand the input state. So let's concentrate on the data structures that
are being pseudoprinted as we finish up the \\{show\_context} procedure.

\Y\P$\4\X318:Pseudoprint the line\X\S$\6
\\{begin\_pseudoprint};\6
\&{if} $\\{buffer}[\\{limit}]=\\{end\_line\_char}$ \1\&{then}\5
$\|j\K\\{limit}$\6
\4\&{else} $\|j\K\\{limit}+1$;\C{determine the effective end of the line}\2\6
\&{if} $\|j>0$ \1\&{then}\6
\&{for} $\|i\K\\{start}\mathrel{\&{to}}\|j-1$ \1\&{do}\6
\&{begin} \37\&{if} $\|i=\\{loc}$ \1\&{then}\5
\\{set\_trick\_count};\2\6
$\\{print}(\\{buffer}[\|i])$;\6
\&{end}\2\2\par
\U section~312.\fi

\M319. \P$\X319:Pseudoprint the token list\X\S$\6
\\{begin\_pseudoprint};\6
\&{if} $\\{token\_type}<\\{macro}$ \1\&{then}\5
$\\{show\_token\_list}(\\{start},\39\\{loc},\39100000)$\6
\4\&{else} $\\{show\_token\_list}(\\{link}(\\{start}),\39\\{loc},\39100000)$%
\C{avoid reference count}\2\par
\U section~312.\fi

\M320. Here is the missing piece of \\{show\_token\_list} that is activated
when the
token beginning line~2 is about to be shown:

\Y\P$\4\X320:Do magic computation\X\S$\6
\\{set\_trick\_count}\par
\U section~292.\fi

\N321.  \[23] Maintaining the input stacks.
The following subroutines change the input status in commonly needed ways.

First comes \\{push\_input}, which stores the current state and creates a
new level (having, initially, the same properties as the old).

\Y\P\D \37$\\{push\_input}\S\hbox{}$\C{enter a new input level, save the old}\6
\&{begin} \37\&{if} $\\{input\_ptr}>\\{max\_in\_stack}$ \1\&{then}\6
\&{begin} \37$\\{max\_in\_stack}\K\\{input\_ptr}$;\6
\&{if} $\\{input\_ptr}=\\{stack\_size}$ \1\&{then}\5
$\\{overflow}(\.{"input\ stack\ size"},\39\\{stack\_size})$;\2\6
\&{end};\2\6
$\\{input\_stack}[\\{input\_ptr}]\K\\{cur\_input}$;\C{stack the record}\6
$\\{incr}(\\{input\_ptr})$;\6
\&{end}\par
\fi

\M322. And of course what goes up must come down.

\Y\P\D \37$\\{pop\_input}\S\hbox{}$\C{leave an input level, re-enter the old}\6
\&{begin} \37$\\{decr}(\\{input\_ptr})$;\5
$\\{cur\_input}\K\\{input\_stack}[\\{input\_ptr}]$;\6
\&{end}\par
\fi

\M323. Here is a procedure that starts a new level of token-list input, given
a token list \|p and its type \|t. If $\|t=\\{macro}$, the calling routine
should
set \\{name} and \\{loc}.

\Y\P\D \37$\\{back\_list}(\#)\S\\{begin\_token\_list}(\#,\39\\{backed\_up})$%
\C{backs up a simple token list}\par
\P\D \37$\\{ins\_list}(\#)\S\\{begin\_token\_list}(\#,\39\\{inserted})$%
\C{inserts a simple token list}\par
\Y\P\4\&{procedure}\1\  \37$\\{begin\_token\_list}(\|p:\\{pointer};\,\35\|t:%
\\{quarterword})$;\2\6
\&{begin} \37\\{push\_input};\5
$\\{state}\K\\{token\_list}$;\5
$\\{start}\K\|p$;\5
$\\{token\_type}\K\|t$;\6
\&{if} $\|t\G\\{macro}$ \1\&{then}\C{the token list starts with a reference
count}\6
\&{begin} \37$\\{add\_token\_ref}(\|p)$;\6
\&{if} $\|t=\\{macro}$ \1\&{then}\5
$\\{param\_start}\K\\{param\_ptr}$\6
\4\&{else} \&{begin} \37$\\{loc}\K\\{link}(\|p)$;\6
\&{if} $\\{tracing\_macros}>1$ \1\&{then}\6
\&{begin} \37\\{begin\_diagnostic};\5
$\\{print\_nl}(\.{""})$;\6
\&{case} $\|t$ \1\&{of}\6
\4\\{mark\_text}: \37$\\{print\_esc}(\.{"mark"})$;\6
\4\\{write\_text}: \37$\\{print\_esc}(\.{"write"})$;\6
\4\&{othercases} \37$\\{print\_cmd\_chr}(\\{assign\_toks},\39\|t-\\{output%
\_text}+\\{output\_routine\_loc})$\2\6
\&{endcases};\6
$\\{print}(\.{"->"})$;\5
$\\{token\_show}(\|p)$;\5
$\\{end\_diagnostic}(\\{false})$;\6
\&{end};\2\6
\&{end};\2\6
\&{end}\6
\4\&{else} $\\{loc}\K\|p$;\2\6
\&{end};\par
\fi

\M324. When a token list has been fully scanned, the following computations
should be done as we leave that level of input. The \\{token\_type} tends
to be equal to either \\{backed\_up} or \\{inserted} about 2/3 of the time.

\Y\P\4\&{procedure}\1\  \37\\{end\_token\_list};\C{leave a token-list input
level}\2\6
\&{begin} \37\&{if} $\\{token\_type}\G\\{backed\_up}$ \1\&{then}\C{token list
to be deleted}\6
\&{begin} \37\&{if} $\\{token\_type}\L\\{inserted}$ \1\&{then}\5
$\\{flush\_list}(\\{start})$\6
\4\&{else} \&{begin} \37$\\{delete\_token\_ref}(\\{start})$;\C{update reference
count}\6
\&{if} $\\{token\_type}=\\{macro}$ \1\&{then}\C{parameters must be flushed}\6
\&{while} $\\{param\_ptr}>\\{param\_start}$ \1\&{do}\6
\&{begin} \37$\\{decr}(\\{param\_ptr})$;\5
$\\{flush\_list}(\\{param\_stack}[\\{param\_ptr}])$;\6
\&{end};\2\2\6
\&{end};\2\6
\&{end}\6
\4\&{else} \&{if} $\\{token\_type}=\\{u\_template}$ \1\&{then}\5
$\\{align\_state}\K0$;\2\2\6
\\{pop\_input};\5
\\{check\_interrupt};\6
\&{end};\par
\fi

\M325. Sometimes \TeX\ has read too far and wants to ``unscan'' what it has
seen. The \\{back\_input} procedure takes care of this by putting the token
just scanned back into the input stream, ready to be read again. This
procedure can be used only if \\{cur\_tok} represents the token to be
replaced. Some applications of \TeX\ use this procedure a lot,
so it has been slightly optimized for speed.

\Y\P\4\&{procedure}\1\  \37\\{back\_input};\C{undoes one token of input}\6
\4\&{var} \37\|p: \37\\{pointer};\C{a token list of length one}\2\6
\&{begin} \37\&{while} $(\\{state}=\\{token\_list})\W(\\{loc}=\\{null})$ \1%
\&{do}\5
\\{end\_token\_list};\C{conserve stack space}\2\6
$\|p\K\\{get\_avail}$;\5
$\\{info}(\|p)\K\\{cur\_tok}$;\6
\&{if} $\\{cur\_tok}<\\{right\_brace\_limit}$ \1\&{then}\6
\&{if} $\\{cur\_tok}<\\{left\_brace\_limit}$ \1\&{then}\5
$\\{decr}(\\{align\_state})$\6
\4\&{else} $\\{incr}(\\{align\_state})$;\2\2\6
\\{push\_input};\5
$\\{state}\K\\{token\_list}$;\5
$\\{start}\K\|p$;\5
$\\{token\_type}\K\\{backed\_up}$;\5
$\\{loc}\K\|p$;\C{that was $\\{back\_list}(\|p)$, without procedure overhead}\6
\&{end};\par
\fi

\M326. \P$\X326:Insert token \|p into \TeX's input\X\S$\6
\&{begin} \37$\|t\K\\{cur\_tok}$;\5
$\\{cur\_tok}\K\|p$;\5
\\{back\_input};\5
$\\{cur\_tok}\K\|t$;\6
\&{end}\par
\U section~282.\fi

\M327. The \\{back\_error} routine is used when we want to replace an offending
token
just before issuing an error message. This routine, like \\{back\_input},
requires that \\{cur\_tok} has been set. We disable interrupts during the
call of \\{back\_input} so that the help message won't be lost.

\Y\P\4\&{procedure}\1\  \37\\{back\_error};\C{back up one token and call %
\\{error}}\2\6
\&{begin} \37$\\{OK\_to\_interrupt}\K\\{false}$;\5
\\{back\_input};\5
$\\{OK\_to\_interrupt}\K\\{true}$;\5
\\{error};\6
\&{end};\7
\4\&{procedure}\1\  \37\\{ins\_error};\C{back up one inserted token and call %
\\{error}}\2\6
\&{begin} \37$\\{OK\_to\_interrupt}\K\\{false}$;\5
\\{back\_input};\5
$\\{token\_type}\K\\{inserted}$;\5
$\\{OK\_to\_interrupt}\K\\{true}$;\5
\\{error};\6
\&{end};\par
\fi

\M328\*. The \\{begin\_file\_reading} procedure starts a new level of input for
lines
of characters to be read from a file, or as an insertion from the
terminal. It does not take care of opening the file, nor does it set \\{loc}
or \\{limit} or \\{line} or \\{page}.

\Y\P\4\&{procedure}\1\  \37\\{begin\_file\_reading};\2\6
\&{begin} \37\&{if} $\\{in\_open}=\\{max\_in\_open}$ \1\&{then}\5
$\\{overflow}(\.{"text\ input\ levels"},\39\\{max\_in\_open})$;\2\6
\&{if} $\\{first}=\\{buf\_size}$ \1\&{then}\5
$\\{overflow}(\.{"buffer\ size"},\39\\{buf\_size})$;\2\6
$\\{incr}(\\{in\_open})$;\5
\\{push\_input};\5
$\\{index}\K\\{in\_open}$;\5
$\\{line\_stack}[\\{index}]\K\\{line}$;\5
$\\{start}\K\\{first}$;\5
$\\{state}\K\\{mid\_line}$;\5
$\\{page\_stack}[\\{index}]\K\\{page}$;\5
$\\{name}\K0$;\C{\\{terminal\_input} is now \\{true}}\6
\&{end};\par
\fi

\M329\*. Conversely, the variables must be downdated when such a level of input
is finished:

\Y\P\4\&{procedure}\1\  \37\\{end\_file\_reading};\2\6
\&{begin} \37$\\{first}\K\\{start}$;\5
$\\{page}\K\\{page\_stack}[\\{index}]$;\5
$\\{line}\K\\{line\_stack}[\\{index}]$;\6
\&{if} $\\{name}>17$ \1\&{then}\5
$\\{a\_close}(\\{cur\_file})$;\C{forget it}\2\6
\\{pop\_input};\5
$\\{decr}(\\{in\_open})$;\6
\&{end};\par
\fi

\M330. In order to keep the stack from overflowing during a long sequence of
inserted `\.{\\show}' commands, the following routine removes completed
error-inserted lines from memory.

\Y\P\4\&{procedure}\1\  \37\\{clear\_for\_error\_prompt};\2\6
\&{begin} \37\&{while} $(\\{state}\I\\{token\_list})\W\\{terminal\_input}\W\30(%
\\{input\_ptr}>0)\W(\\{loc}>\\{limit})$ \1\&{do}\5
\\{end\_file\_reading};\2\6
\\{print\_ln};\5
\\{clear\_terminal};\6
\&{end};\par
\fi

\M331. To get \TeX's whole input mechanism going, we perform the following
actions.

\Y\P$\4\X331:Initialize the input routines\X\S$\6
\&{begin} \37$\\{input\_ptr}\K0$;\5
$\\{max\_in\_stack}\K0$;\5
$\\{in\_open}\K0$;\5
$\\{max\_buf\_stack}\K0$;\5
$\\{param\_ptr}\K0$;\5
$\\{max\_param\_stack}\K0$;\5
$\\{first}\K\\{buf\_size}$;\6
\1\&{repeat} \37$\\{buffer}[\\{first}]\K0$;\5
$\\{decr}(\\{first})$;\6
\4\&{until}\5
$\\{first}=0$;\2\6
$\\{scanner\_status}\K\\{normal}$;\5
$\\{warning\_index}\K\\{null}$;\5
$\\{first}\K1$;\5
$\\{state}\K\\{new\_line}$;\5
$\\{start}\K1$;\5
$\\{index}\K0$;\5
$\\{line}\K0$;\5
$\\{name}\K0$;\5
$\\{force\_eof}\K\\{false}$;\5
$\\{align\_state}\K1000000$;\6
\&{if} $\R\\{init\_terminal}$ \1\&{then}\5
\&{goto} \37\\{final\_end};\2\6
$\\{limit}\K\\{last}$;\5
$\\{first}\K\\{last}+1$;\C{\\{init\_terminal} has set \\{loc} and \\{last}}\6
\&{end}\par
\U section~1337.\fi

\N332.  \[24] Getting the next token.
The heart of \TeX's input mechanism is the \\{get\_next} procedure, which
we shall develop in the next few sections of the program. Perhaps we
shouldn't actually call it the ``heart,'' however, because it really acts
as \TeX's eyes and mouth, reading the source files and gobbling them up.
And it also helps \TeX\ to regurgitate stored token lists that are to be
processed again.

The main duty of \\{get\_next} is to input one token and to set \\{cur\_cmd}
and \\{cur\_chr} to that token's command code and modifier. Furthermore, if
the input token is a control sequence, the \\{eqtb} location of that control
sequence is stored in \\{cur\_cs}; otherwise \\{cur\_cs} is set to zero.

Underlying this simple description is a certain amount of complexity
because of all the cases that need to be handled, as explained above.
However, the inner loop of \\{get\_next} is reasonably short and fast.

When \\{get\_next} is asked to get the next token of a \.{\\read} line,
it sets $\\{cur\_cmd}=\\{cur\_chr}=\\{cur\_cs}=0$ in the case that no more
tokens
appear on that line. (There might not be any tokens at all, if the
\\{end\_line\_char} has \\{ignore} as its catcode.)

\fi

\M333. The value of \\{par\_loc} is the \\{eqtb} address of `\.{\\par}'. This
quantity
is needed because a blank line of input is supposed to be exactly equivalent
to the appearance of \.{\\par}; we must set $\\{cur\_cs}\K\\{par\_loc}$
when detecting a blank line.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{par\_loc}: \37\\{pointer};\C{location of `\.{\\par}' in \\{eqtb}}\6
\4\\{par\_token}: \37\\{halfword};\C{token representing '\.{\\par}'}\par
\fi

\M334. \P$\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}%
\S$\6
$\\{primitive}(\.{"par"},\39\\{par\_end},\390)$;\5
$\\{par\_loc}\K\\{cur\_val}$;\5
$\\{par\_token}\K\\{cs\_token\_flag}+\\{par\_loc}$;\par
\fi

\M335. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{par\_end}: \37$\\{print\_esc}(\.{"par"})$;\par
\fi

\M336\*. Before getting into \\{get\_next}, let's consider the subroutine that
is called when an `\.{\\outer}' control sequence has been scanned or
when the end of a file has been reached. These two cases are distinguished
by \\{cur\_cs}, which is zero at the end of a file.

\Y\P\4\&{procedure}\1\  \37\\{check\_outer\_validity};\6
\4\&{var} \37\|p: \37\\{pointer};\C{points to inserted token list}\6
\|q: \37\\{pointer};\C{auxiliary pointer}\2\6
\&{begin} \37\&{if} $\\{scanner\_status}\I\\{normal}$ \1\&{then}\6
\&{begin} \37$\\{deletions\_allowed}\K\\{false}$;\5
\X337:Back up an outer control sequence so that it can be reread\X;\6
\&{if} $\\{scanner\_status}>\\{skipping}$ \1\&{then}\5
\X338:Tell the user what has run away and try to recover\X\6
\4\&{else} \&{begin} \37$\\{print\_err}(\.{"Incomplete\ "})$;\5
$\\{print\_cmd\_chr}(\\{if\_test},\39\\{cur\_if})$;\5
$\\{print}(\.{";\ all\ text\ was\ ignored\ after\ line\ "})$;\5
$\\{print\_int}(\\{skip\_line})$;\6
\&{if} $\\{skip\_page}>1$ \1\&{then}\6
\&{begin} \37$\\{print}(\.{",\ p."})$;\5
$\\{print\_int}(\\{skip\_page})$;\6
\&{end};\2\6
$\\{help3}(\.{"A\ forbidden\ control\ sequence\ occurred\ in\ skipped\
text."})$\6
$(\.{"This\ kind\ of\ error\ happens\ when\ you\ say\ \`\\if...\'\ and\
forget"})$\6
$(\.{"the\ matching\ \`\\fi\'.\ I\'ve\ inserted\ a\ \`\\fi\';\ this\ might\
work."})$;\6
\&{if} $\\{cur\_cs}\I0$ \1\&{then}\5
$\\{cur\_cs}\K0$\6
\4\&{else} $\\{help\_line}[2]\K\30\.{"The\ file\ ended\ while\ I\ was\ skipping%
\ conditional\ text."}$;\2\6
$\\{cur\_tok}\K\\{cs\_token\_flag}+\\{frozen\_fi}$;\5
\\{ins\_error};\6
\&{end};\2\6
$\\{deletions\_allowed}\K\\{true}$;\6
\&{end};\2\6
\&{end};\par
\fi

\M337. An outer control sequence that occurs in a \.{\\read} will not be
reread,
since the error recovery for \.{\\read} is not very powerful.

\Y\P$\4\X337:Back up an outer control sequence so that it can be reread\X\S$\6
\&{if} $\\{cur\_cs}\I0$ \1\&{then}\6
\&{begin} \37\&{if} $(\\{state}=\\{token\_list})\V(\\{name}<1)\V(\\{name}>17)$ %
\1\&{then}\6
\&{begin} \37$\|p\K\\{get\_avail}$;\5
$\\{info}(\|p)\K\\{cs\_token\_flag}+\\{cur\_cs}$;\5
$\\{back\_list}(\|p)$;\C{prepare to read the control sequence again}\6
\&{end};\2\6
$\\{cur\_cmd}\K\\{spacer}$;\5
$\\{cur\_chr}\K\.{"\ "}$;\C{replace it by a space}\6
\&{end}\2\par
\U section~336\*.\fi

\M338. \P$\X338:Tell the user what has run away and try to recover\X\S$\6
\&{begin} \37\\{runaway};\C{print a definition, argument, or preamble}\6
\&{if} $\\{cur\_cs}=0$ \1\&{then}\5
$\\{print\_err}(\.{"File\ ended"})$\6
\4\&{else} \&{begin} \37$\\{cur\_cs}\K0$;\5
$\\{print\_err}(\.{"Forbidden\ control\ sequence\ found"})$;\6
\&{end};\2\6
$\\{print}(\.{"\ while\ scanning\ "})$;\5
\X339:Print either `\.{definition}' or `\.{use}' or `\.{preamble}' or `%
\.{text}', and insert tokens that should lead to recovery\X;\6
$\\{print}(\.{"\ of\ "})$;\5
$\\{sprint\_cs}(\\{warning\_index})$;\5
$\\{help4}(\.{"I\ suspect\ you\ have\ forgotten\ a\ \`\}\',\ causing\ me"})$\6
$(\.{"to\ read\ past\ where\ you\ wanted\ me\ to\ stop."})$\6
$(\.{"I\'ll\ try\ to\ recover;\ but\ if\ the\ error\ is\ serious,"})$\6
$(\.{"you\'d\ better\ type\ \`E\'\ or\ \`X\'\ now\ and\ fix\ your\ file."})$;\6
\\{error};\6
\&{end}\par
\U section~336\*.\fi

\M339. The recovery procedure can't be fully understood without knowing more
about the \TeX\ routines that should be aborted, but we can sketch the
ideas here:  For a runaway definition we will insert a right brace; for a
runaway preamble, we will insert a special \.{\\cr} token and a right
brace; and for a runaway argument, we will set \\{long\_state} to
\\{outer\_call} and insert \.{\\par}.

\Y\P$\4\X339:Print either `\.{definition}' or `\.{use}' or `\.{preamble}' or `%
\.{text}', and insert tokens that should lead to recovery\X\S$\6
$\|p\K\\{get\_avail}$;\6
\&{case} $\\{scanner\_status}$ \1\&{of}\6
\4\\{defining}: \37\&{begin} \37$\\{print}(\.{"definition"})$;\5
$\\{info}(\|p)\K\\{right\_brace\_token}+\.{"\}"}$;\6
\&{end};\6
\4\\{matching}: \37\&{begin} \37$\\{print}(\.{"use"})$;\5
$\\{info}(\|p)\K\\{par\_token}$;\5
$\\{long\_state}\K\\{outer\_call}$;\6
\&{end};\6
\4\\{aligning}: \37\&{begin} \37$\\{print}(\.{"preamble"})$;\5
$\\{info}(\|p)\K\\{right\_brace\_token}+\.{"\}"}$;\5
$\|q\K\|p$;\5
$\|p\K\\{get\_avail}$;\5
$\\{link}(\|p)\K\|q$;\5
$\\{info}(\|p)\K\\{cs\_token\_flag}+\\{frozen\_cr}$;\5
$\\{align\_state}\K-1000000$;\6
\&{end};\6
\4\\{absorbing}: \37\&{begin} \37$\\{print}(\.{"text"})$;\5
$\\{info}(\|p)\K\\{right\_brace\_token}+\.{"\}"}$;\6
\&{end};\2\6
\&{end};\C{there are no other cases}\6
$\\{ins\_list}(\|p)$\par
\U section~338.\fi

\M340. We need to mention a procedure here that may be called by \\{get\_next}.

\Y\P\4\&{procedure}\1\  \37\\{firm\_up\_the\_line};\5
\\{forward};\par
\fi

\M341\*. Now we're ready to take the plunge into \\{get\_next} itself. Parts of
this routine are executed more often than any other instructions of \TeX.

\Y\P\D \37$\\{switch}=25$\C{a label in \\{get\_next}}\par
\P\D \37$\\{start\_cs}=26$\C{another}\par
\Y\P\4\&{procedure}\1\  \37\\{get\_next};\C{sets \\{cur\_cmd}, \\{cur\_chr}, %
\\{cur\_cs} to next token}\6
\4\&{label} \37$\\{restart},\39$\C{go here to get the next input token}\6
$\\{switch},\39$\C{go here to eat the next character from a file}\6
$\\{reswitch},\39$\C{go here to digest it again}\6
$\\{start\_cs},\39$\C{go here to start looking for a control sequence}\6
$\\{found},\39$\C{go here when a control sequence has been found}\6
\\{exit};\C{go here when the next input token has been got}\6
\4\&{var} \37\|k: \37$0\to\\{buf\_size}$;\C{an index into \\{buffer}}\6
\|t: \37\\{halfword};\C{a token}\6
\\{cat}: \37$0\to15$;\C{$\\{cat\_code}(\\{cur\_chr})$, usually}\2\6
\&{begin} \37\\{restart}: \37$\\{cur\_cs}\K0$;\6
\&{if} $\\{state}\I\\{token\_list}$ \1\&{then}\5
\X343:Input from external file, \&{goto} \\{restart} if no input found\X\6
\4\&{else} \X357:Input from token list, \&{goto} \\{restart} if end of list or
if a parameter needs to be expanded\X;\2\6
\X342:If an alignment entry has just ended, take appropriate action\X;\6
\4\\{exit}: \37\&{if} $\\{tracing\_stats}>2$ \1\&{then}\6
\&{begin} \37$\|k\K\\{trace\_depth}$;\5
$\\{print\_nl}(\.{""})$;\6
\&{while} $\|k>0$ \1\&{do}\6
\&{begin} \37$\\{print}(\.{"\ "})$;\5
$\\{decr}(\|k)$;\6
\&{end};\2\6
$\\{print}(\.{"|"})$;\5
$\\{print\_char}(\.{"\ "})$;\6
\&{if} $\\{cur\_cs}>0$ \1\&{then}\6
\&{begin} \37$\\{print\_cs}(\\{cur\_cs})$;\5
$\\{print\_char}(\.{"="})$;\6
\&{end};\2\6
$\\{print\_cmd\_chr}(\\{cur\_cmd},\39\\{cur\_chr})$;\6
\&{end};\2\6
\&{end};\par
\fi

\M342. An alignment entry ends when a tab or \.{\\cr} occurs, provided that the
current level of braces is the same as the level that was present at the
beginning of that alignment entry; i.e., provided that \\{align\_state} has
returned to the value it had after the \<u_j> template for that entry.

\Y\P$\4\X342:If an alignment entry has just ended, take appropriate action\X\S$%
\6
\&{if} $\\{cur\_cmd}\L\\{car\_ret}$ \1\&{then}\6
\&{if} $\\{cur\_cmd}\G\\{tab\_mark}$ \1\&{then}\6
\&{if} $\\{align\_state}=0$ \1\&{then}\5
\X789:Insert the \(v)\<v_j> template and \&{goto} \\{restart}\X\2\2\2\par
\U section~341\*.\fi

\M343. \P$\X343:Input from external file, \&{goto} \\{restart} if no input
found\X\S$\6
\&{begin} \37\\{switch}: \37\&{if} $\\{loc}\L\\{limit}$ \1\&{then}\C{current
line not yet finished}\6
\&{begin} \37$\\{cur\_chr}\K\\{buffer}[\\{loc}]$;\5
$\\{incr}(\\{loc})$;\6
\4\\{reswitch}: \37$\\{cur\_cmd}\K\\{cat\_code}(\\{cur\_chr})$;\5
\X344:Change state if necessary, and \&{goto} \\{switch} if the current
character should be ignored, or \&{goto} \\{reswitch} if the current character
changes to another\X;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{state}\K\\{new\_line}$;\6
\X360:Move to next line of file, or \&{goto} \\{restart} if there is no next
line, or \&{return} if a \.{\\read} line has finished\X;\6
\\{check\_interrupt};\5
\&{goto} \37\\{switch};\6
\&{end};\2\6
\&{end}\par
\U section~341\*.\fi

\M344. The following 48-way switch accomplishes the scanning quickly, assuming
that a decent \PASCAL\ compiler has translated the code. Note that the numeric
values for \\{mid\_line}, \\{skip\_blanks}, and \\{new\_line} are spaced
apart from each other by $\\{max\_char\_code}+1$, so we can add a character's
command code to the state to get a single number that characterizes both.

\Y\P\D \37$\\{any\_state\_plus}(\#)\S\\{mid\_line}+\#,\39\\{skip\_blanks}+\#,%
\39\\{new\_line}+\#$\par
\Y\P$\4\X344:Change state if necessary, and \&{goto} \\{switch} if the current
character should be ignored, or \&{goto} \\{reswitch} if the current character
changes to another\X\S$\6
\&{case} $\\{state}+\\{cur\_cmd}$ \1\&{of}\6
\4\X345:Cases where character is ignored\X: \37\&{goto} \37\\{switch};\6
\4$\\{any\_state\_plus}(\\{escape})$: \37\X354:Scan a control sequence and set
$\\{state}\K\\{skip\_blanks}$ or \\{mid\_line}\X;\6
\4$\\{any\_state\_plus}(\\{active\_char})$: \37\X353:Process an
active-character control sequence and set $\\{state}\K\\{mid\_line}$\X;\6
\4$\\{any\_state\_plus}(\\{sup\_mark})$: \37\X352:If this \\{sup\_mark} starts
a control character like~\.{\↑\↑A}, then \&{goto} \\{reswitch}, otherwise set $%
\\{state}\K\\{mid\_line}$\X;\6
\4$\\{any\_state\_plus}(\\{invalid\_char})$: \37\X346:Decry the invalid
character and \&{goto} \\{restart}\X;\6
\hbox{\4}\X347:Handle situations involving spaces, braces, changes of state\X\6
\4\&{othercases} \37\\{do\_nothing}\2\6
\&{endcases}\par
\U section~343.\fi

\M345. \P$\X345:Cases where character is ignored\X\S$\6
$\\{any\_state\_plus}(\\{ignore}),\39\\{skip\_blanks}+\\{spacer},\39\\{new%
\_line}+\\{spacer}$\par
\U section~344.\fi

\M346. We go to \\{restart} instead of to \\{switch}, because \\{state} might
equal
\\{token\_list} after the error has been dealt with
(cf.\ \\{clear\_for\_error\_prompt}).

\Y\P$\4\X346:Decry the invalid character and \&{goto} \\{restart}\X\S$\6
\&{begin} \37$\\{print\_err}(\.{"Text\ line\ contains\ an\ invalid\
character"})$;\5
$\\{help2}(\.{"A\ funny\ symbol\ that\ I\ can\'t\ read\ has\ just\ been\
input."})$\6
$(\.{"Continue,\ and\ I\'ll\ forget\ that\ it\ ever\ happened."})$;\6
$\\{deletions\_allowed}\K\\{false}$;\5
\\{error};\5
$\\{deletions\_allowed}\K\\{true}$;\5
\&{goto} \37\\{restart};\6
\&{end}\par
\U section~344.\fi

\M347. \P\D \37$\\{add\_delims\_to}(\#)\S\#+\\{math\_shift},\39\#+\\{tab%
\_mark},\39\#+\\{mac\_param},\39\#+\\{sub\_mark},\39\#+\\{letter},\39\#+%
\\{other\_char}$\par
\Y\P$\4\X347:Handle situations involving spaces, braces, changes of state\X\S$\6
\4$\\{mid\_line}+\\{spacer}$: \37\X349:Enter \\{skip\_blanks} state, emit a
space\X;\6
\4$\\{mid\_line}+\\{car\_ret}$: \37\X348:Finish line, emit a space\X;\6
\4$\\{skip\_blanks}+\\{car\_ret},\39\\{any\_state\_plus}(\\{comment})$: \37%
\X350:Finish line, \&{goto} \\{switch}\X;\6
\4$\\{new\_line}+\\{car\_ret}$: \37\X351:Finish line, emit a \.{\\par}\X;\6
\4$\\{mid\_line}+\\{left\_brace}$: \37$\\{incr}(\\{align\_state})$;\6
\4$\\{skip\_blanks}+\\{left\_brace},\39\\{new\_line}+\\{left\_brace}$: \37%
\&{begin} \37$\\{state}\K\\{mid\_line}$;\5
$\\{incr}(\\{align\_state})$;\6
\&{end};\6
\4$\\{mid\_line}+\\{right\_brace}$: \37$\\{decr}(\\{align\_state})$;\6
\4$\\{skip\_blanks}+\\{right\_brace},\39\\{new\_line}+\\{right\_brace}$: \37%
\&{begin} \37$\\{state}\K\\{mid\_line}$;\5
$\\{decr}(\\{align\_state})$;\6
\&{end};\6
\4$\\{add\_delims\_to}(\\{skip\_blanks}),\39\\{add\_delims\_to}(\\{new%
\_line})$: \37$\\{state}\K\\{mid\_line}$;\par
\U section~344.\fi

\M348. When a character of type \\{spacer} gets through, its character code is
changed to $\.{"\ "}=\O{40}$. This means that the ASCII codes for tab and
space,
and for the space inserted at the end of a line, will
be treated alike when macro parameters are being matched. We do this
since such characters are indistinguishable on most computer terminal displays.

\Y\P$\4\X348:Finish line, emit a space\X\S$\6
\&{begin} \37$\\{loc}\K\\{limit}+1$;\5
$\\{cur\_cmd}\K\\{spacer}$;\5
$\\{cur\_chr}\K\.{"\ "}$;\6
\&{end}\par
\U section~347.\fi

\M349. The following code is performed only when $\\{cur\_cmd}=\\{spacer}$.

\Y\P$\4\X349:Enter \\{skip\_blanks} state, emit a space\X\S$\6
\&{begin} \37$\\{state}\K\\{skip\_blanks}$;\5
$\\{cur\_chr}\K\.{"\ "}$;\6
\&{end}\par
\U section~347.\fi

\M350. \P$\X350:Finish line, \&{goto} \\{switch}\X\S$\6
\&{begin} \37$\\{loc}\K\\{limit}+1$;\5
\&{goto} \37\\{switch};\6
\&{end}\par
\U section~347.\fi

\M351. \P$\X351:Finish line, emit a \.{\\par}\X\S$\6
\&{begin} \37$\\{loc}\K\\{limit}+1$;\5
$\\{cur\_cs}\K\\{par\_loc}$;\5
$\\{cur\_cmd}\K\\{eq\_type}(\\{cur\_cs})$;\5
$\\{cur\_chr}\K\\{equiv}(\\{cur\_cs})$;\6
\&{if} $\\{cur\_cmd}\G\\{outer\_call}$ \1\&{then}\5
\\{check\_outer\_validity};\2\6
\&{end}\par
\U section~347.\fi

\M352. \P$\X352:If this \\{sup\_mark} starts a control character like~\.{\↑%
\↑A}, then \&{goto} \\{reswitch}, otherwise set $\\{state}\K\\{mid\_line}$\X\S$%
\6
\&{begin} \37\&{if} $(\\{cur\_chr}=\\{buffer}[\\{loc}])\W(\\{loc}<\\{limit})$ %
\1\&{then}\6
\&{begin} \37\&{if} $\\{buffer}[\\{loc}+1]<\O{100}$ \1\&{then}\5
$\\{cur\_chr}\K\\{buffer}[\\{loc}+1]+\O{100}$\6
\4\&{else} $\\{cur\_chr}\K\\{buffer}[\\{loc}+1]-\O{100}$;\2\6
$\\{loc}\K\\{loc}+2$;\5
\&{goto} \37\\{reswitch};\6
\&{end};\2\6
$\\{state}\K\\{mid\_line}$;\6
\&{end}\par
\U section~344.\fi

\M353. \P$\X353:Process an active-character control sequence and set $\\{state}%
\K\\{mid\_line}$\X\S$\6
\&{begin} \37$\\{cur\_cs}\K\\{cur\_chr}+\\{active\_base}$;\5
$\\{cur\_cmd}\K\\{eq\_type}(\\{cur\_cs})$;\5
$\\{cur\_chr}\K\\{equiv}(\\{cur\_cs})$;\5
$\\{state}\K\\{mid\_line}$;\6
\&{if} $\\{cur\_cmd}\G\\{outer\_call}$ \1\&{then}\5
\\{check\_outer\_validity};\2\6
\&{end}\par
\U section~344.\fi

\M354. Control sequence names are scanned only when they appear in some line of
a file; once they have been scanned the first time, their \\{eqtb} location
serves as a unique identification, so \TeX\ doesn't need to refer to the
original name any more except when it prints the equivalent in symbolic form.

The program that scans a control sequence has been written carefully
in order to avoid the blowups that might otherwise occur if a malicious
user tried something like `\.{\\catcode\'15=0}'. The algorithm might
look at $\\{buffer}[\\{limit}+1]$, but it never looks at $\\{buffer}[%
\\{limit}+2]$.

If expanded control characters like `\.{\↑\↑A}' appear in or just following
a control sequence name, they are converted to single characters in the
buffer and the process is repeated, slowly but surely.

\Y\P$\4\X354:Scan a control sequence and set $\\{state}\K\\{skip\_blanks}$ or %
\\{mid\_line}\X\S$\6
\&{begin} \37\&{if} $\\{loc}>\\{limit}$ \1\&{then}\5
$\\{cur\_cs}\K\\{null\_cs}$\C{\\{state} is irrelevant in this case}\6
\4\&{else} \&{begin} \37\\{start\_cs}: \37$\|k\K\\{loc}$;\5
$\\{cur\_chr}\K\\{buffer}[\|k]$;\5
$\\{cat}\K\\{cat\_code}(\\{cur\_chr})$;\5
$\\{incr}(\|k)$;\6
\&{if} $\\{cat}=\\{letter}$ \1\&{then}\5
$\\{state}\K\\{skip\_blanks}$\6
\4\&{else} \&{if} $\\{cat}=\\{spacer}$ \1\&{then}\5
$\\{state}\K\\{skip\_blanks}$\6
\4\&{else} $\\{state}\K\\{mid\_line}$;\2\2\6
\&{if} $(\\{cat}=\\{letter})\W(\|k\L\\{limit})$ \1\&{then}\5
\X356:Scan ahead in the buffer until finding a nonletter; if an expanded
control code is encountered, reduce it and \&{goto} \\{start\_cs}; otherwise if
a multiletter control sequence is found, adjust \\{cur\_cs} and \\{loc}, and %
\&{goto} \\{found}\X\6
\4\&{else} \X355:If an expanded control code is present, reduce it and \&{goto}
\\{start\_cs}\X;\2\6
$\\{cur\_cs}\K\\{single\_base}+\\{buffer}[\\{loc}]$;\5
$\\{incr}(\\{loc})$;\6
\&{end};\2\6
\4\\{found}: \37$\\{cur\_cmd}\K\\{eq\_type}(\\{cur\_cs})$;\5
$\\{cur\_chr}\K\\{equiv}(\\{cur\_cs})$;\6
\&{if} $\\{cur\_cmd}\G\\{outer\_call}$ \1\&{then}\5
\\{check\_outer\_validity};\2\6
\&{end}\par
\U section~344.\fi

\M355. Whenever we reach the following piece of code, we will have
$\\{cur\_chr}=\\{buffer}[\|k-1]$ and $\|k\L\\{limit}+1$ and $\\{cat}=\\{cat%
\_code}(\\{cur\_chr})$. If an
expanded control code like \.{\↑\↑A} appears in $\\{buffer}[(\|k-1)\to(%
\|k+1)]$, we
will store the corresponding code in $\\{buffer}[\|k-1]$ and shift the rest of
the buffer left two places.  The value of \\{cur\_chr} may be changed here,
but not the value of \\{cat}.

\Y\P$\4\X355:If an expanded control code is present, reduce it and \&{goto} %
\\{start\_cs}\X\S$\6
\&{begin} \37\&{if} $\\{buffer}[\|k]=\\{cur\_chr}$ \1\&{then}\6
\&{if} $\\{cat}=\\{sup\_mark}$ \1\&{then}\6
\&{if} $\|k<\\{limit}$ \1\&{then}\6
\&{begin} \37$\\{cur\_chr}\K\\{buffer}[\|k+1]$;\6
\&{if} $\\{cur\_chr}<\O{100}$ \1\&{then}\5
$\\{buffer}[\|k-1]\K\\{cur\_chr}+\O{100}$\6
\4\&{else} $\\{buffer}[\|k-1]\K\\{cur\_chr}-\O{100}$;\2\6
$\\{limit}\K\\{limit}-2$;\5
$\\{first}\K\\{first}-2$;\6
\&{while} $\|k\L\\{limit}$ \1\&{do}\6
\&{begin} \37$\\{buffer}[\|k]\K\\{buffer}[\|k+2]$;\5
$\\{incr}(\|k)$;\6
\&{end};\2\6
\&{goto} \37\\{start\_cs};\6
\&{end};\2\2\2\6
\&{end}\par
\U sections~354 and~356.\fi

\M356. \P$\X356:Scan ahead in the buffer until finding a nonletter; if an
expanded control code is encountered, reduce it and \&{goto} \\{start\_cs};
otherwise if a multiletter control sequence is found, adjust \\{cur\_cs} and %
\\{loc}, and \&{goto} \\{found}\X\S$\6
\&{begin} \37\1\&{repeat} \37$\\{cur\_chr}\K\\{buffer}[\|k]$;\5
$\\{cat}\K\\{cat\_code}(\\{cur\_chr})$;\5
$\\{incr}(\|k)$;\6
\4\&{until}\5
$(\\{cat}\I\\{letter})\V(\|k>\\{limit})$;\2\6
\X355:If an expanded control code is present, reduce it and \&{goto} \\{start%
\_cs}\X;\6
\&{if} $\\{cat}\I\\{letter}$ \1\&{then}\5
$\\{decr}(\|k)$;\C{now \|k points to first nonletter}\2\6
\&{if} $\|k>\\{loc}+1$ \1\&{then}\C{multiletter control sequence has been
scanned}\6
\&{begin} \37$\\{cur\_cs}\K\\{id\_lookup}(\\{loc},\39\|k-\\{loc})$;\5
$\\{loc}\K\|k$;\5
\&{goto} \37\\{found};\6
\&{end};\2\6
\&{end}\par
\U section~354.\fi

\M357. Let's consider now what happens when \\{get\_next} is looking at a token
list.

\Y\P$\4\X357:Input from token list, \&{goto} \\{restart} if end of list or if a
parameter needs to be expanded\X\S$\6
\&{if} $\\{loc}\I\\{null}$ \1\&{then}\C{list not exhausted}\6
\&{begin} \37$\|t\K\\{info}(\\{loc})$;\5
$\\{loc}\K\\{link}(\\{loc})$;\C{move to next}\6
\&{if} $\|t\G\\{cs\_token\_flag}$ \1\&{then}\C{a control sequence token}\6
\&{begin} \37$\\{cur\_cs}\K\|t-\\{cs\_token\_flag}$;\5
$\\{cur\_cmd}\K\\{eq\_type}(\\{cur\_cs})$;\5
$\\{cur\_chr}\K\\{equiv}(\\{cur\_cs})$;\6
\&{if} $\\{cur\_cmd}\G\\{outer\_call}$ \1\&{then}\6
\&{if} $\\{cur\_cmd}=\\{dont\_expand}$ \1\&{then}\5
\X358:Get the next token, suppressing expansion\X\6
\4\&{else} \\{check\_outer\_validity};\2\2\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{cur\_cmd}\K\|t\mathbin{\&{div}}\O{400}$;\5
$\\{cur\_chr}\K\|t\mathbin{\&{mod}}\O{400}$;\6
\&{case} $\\{cur\_cmd}$ \1\&{of}\6
\4\\{left\_brace}: \37$\\{incr}(\\{align\_state})$;\6
\4\\{right\_brace}: \37$\\{decr}(\\{align\_state})$;\6
\4\\{out\_param}: \37\X359:Insert macro parameter and \&{goto} \\{restart}\X;\6
\4\&{othercases} \37\\{do\_nothing}\2\6
\&{endcases};\6
\&{end};\2\6
\&{end}\6
\4\&{else} \&{begin} \37\C{we are done with this token list}\6
\\{end\_token\_list};\5
\&{goto} \37\\{restart};\C{resume previous level}\6
\&{end}\2\par
\U section~341\*.\fi

\M358. The present point in the program is reached only when the \\{no\_expand}
routine has inserted a special marker into the input. In this special
case, $\\{info}(\\{loc})$ is known to be a control sequence token, and $%
\\{link}(\\{loc})=\\{null}$.

\Y\P\D \37$\\{no\_expand\_flag}=257$\C{this characterizes a special variant of %
\\{relax}}\par
\Y\P$\4\X358:Get the next token, suppressing expansion\X\S$\6
\&{begin} \37$\\{cur\_cs}\K\\{info}(\\{loc})-\\{cs\_token\_flag}$;\5
$\\{loc}\K\\{null}$;\6
$\\{cur\_cmd}\K\\{eq\_type}(\\{cur\_cs})$;\5
$\\{cur\_chr}\K\\{equiv}(\\{cur\_cs})$;\6
\&{if} $\\{cur\_cmd}>\\{max\_command}$ \1\&{then}\6
\&{begin} \37$\\{cur\_cmd}\K\\{relax}$;\5
$\\{cur\_chr}\K\\{no\_expand\_flag}$;\6
\&{end};\2\6
\&{end}\par
\U section~357.\fi

\M359. \P$\X359:Insert macro parameter and \&{goto} \\{restart}\X\S$\6
\&{begin} \37$\\{begin\_token\_list}(\\{param\_stack}[\\{param\_start}+\\{cur%
\_chr}-1],\39\\{parameter})$;\5
\&{goto} \37\\{restart};\6
\&{end}\par
\U section~357.\fi

\M360. All of the easy branches of \\{get\_next} have now been taken care of.
There is one more branch.

\Y\P$\4\X360:Move to next line of file, or \&{goto} \\{restart} if there is no
next line, or \&{return} if a \.{\\read} line has finished\X\S$\6
\&{if} $\\{name}>17$ \1\&{then}\5
\X362:Read next line of file into \\{buffer}, or \&{goto} \\{restart} if the
file has ended\X\6
\4\&{else} \&{begin} \37\&{if} $\R\\{terminal\_input}$ \1\&{then}\C{\.{\\read}
line has ended}\6
\&{begin} \37$\\{cur\_cmd}\K0$;\5
$\\{cur\_chr}\K0$;\5
\&{return};\6
\&{end};\2\6
\&{if} $\\{input\_ptr}>0$ \1\&{then}\C{text was inserted during error recovery}%
\6
\&{begin} \37\\{end\_file\_reading};\5
\&{goto} \37\\{restart};\C{resume previous level}\6
\&{end};\2\6
\&{if} $\\{selector}<\\{log\_only}$ \1\&{then}\5
\\{open\_log\_file};\2\6
\&{if} $\\{interaction}>\\{nonstop\_mode}$ \1\&{then}\6
\&{begin} \37\&{if} $(\\{end\_line\_char}<0)\V(\\{end\_line\_char}>127)$ \1%
\&{then}\5
$\\{incr}(\\{limit})$;\2\6
\&{if} $\\{limit}=\\{start}$ \1\&{then}\C{previous line was empty}\6
$\\{print\_nl}(\.{"(Please\ type\ a\ command\ or\ say\ \`\\end\')"})$;\2\6
\\{print\_ln};\5
$\\{first}\K\\{start}$;\5
$\\{prompt\_input}(\.{"*"})$;\C{input on-line into \\{buffer}}\6
$\\{limit}\K\\{last}$;\6
\&{if} $(\\{end\_line\_char}<0)\V(\\{end\_line\_char}>127)$ \1\&{then}\5
$\\{decr}(\\{limit})$\6
\4\&{else} $\\{buffer}[\\{limit}]\K\\{end\_line\_char}$;\2\6
$\\{first}\K\\{limit}+1$;\5
$\\{loc}\K\\{start}$;\6
\&{end}\6
\4\&{else} $\\{fatal\_error}(\.{"***\ (job\ aborted,\ no\ legal\ \\end\
found)"})$;\C{nonstop mode, which is intended for overnight batch processing,
		never waits for on-line input}\2\6
\&{end}\2\par
\U section~343.\fi

\M361. The global variable \\{force\_eof} is normally \\{false}; it is set %
\\{true}
by an \.{\\endinput} command.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{force\_eof}: \37\\{boolean};\C{should the next \.{\\input} be aborted
early?}\par
\fi

\M362. \P$\X362:Read next line of file into \\{buffer}, or \&{goto} \\{restart}
if the file has ended\X\S$\6
\&{begin} \37$\\{incr}(\\{line})$;\5
$\\{first}\K\\{start}$;\6
\&{if} $\R\\{force\_eof}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{input\_ln}(\\{cur\_file},\39\\{true})$ \1\&{then}\C{not
end of file}\6
\\{firm\_up\_the\_line}\C{this sets \\{limit}}\6
\4\&{else} $\\{force\_eof}\K\\{true}$;\2\6
\&{end};\2\6
\&{if} $\\{force\_eof}$ \1\&{then}\6
\&{begin} \37$\\{print\_char}(\.{")"})$;\5
$\\{force\_eof}\K\\{false}$;\5
\\{update\_terminal};\C{show user that file has been read}\6
\\{end\_file\_reading};\C{resume previous level}\6
\\{check\_outer\_validity};\5
\&{goto} \37\\{restart};\6
\&{end};\2\6
\&{if} $(\\{end\_line\_char}<0)\V(\\{end\_line\_char}>127)$ \1\&{then}\5
$\\{decr}(\\{limit})$\6
\4\&{else} $\\{buffer}[\\{limit}]\K\\{end\_line\_char}$;\2\6
$\\{first}\K\\{limit}+1$;\5
$\\{loc}\K\\{start}$;\C{ready to read}\6
\&{end}\par
\U section~360.\fi

\M363\*. If the user has set the \\{pausing} parameter to some positive value,
and if nonstop mode has not been selected,
each line of input is displayed in the transcript file, followed by `\.{=>}',
and also put into the user's line-editor buffer.
\TeX\ waits for the line to be edited, and the next line received is
used instead of the line in the file.

\Y\P\4\&{procedure}\1\  \37\\{firm\_up\_the\_line};\6
\4\&{var} \37\|k: \37$0\to\\{buf\_size}$;\C{an index into \\{buffer}}\2\6
\&{begin} \37$\\{limit}\K\\{last}$;\6
\&{if} $\\{pausing}>0$ \1\&{then}\6
\&{if} $\\{interaction}>\\{nonstop\_mode}$ \1\&{then}\6
\&{if} $\\{buffer}[\\{start}]\I\\{form\_feed}$ \1\&{then}\6
\&{begin} \37\\{wake\_up\_terminal};\5
\\{print\_ln};\6
\&{if} $\\{start}=\\{limit}$ \1\&{then}\C{empty line will be made nonempty so
that it's visible}\6
\&{begin} \37$\\{buffer}[\\{start}]\K\.{"\ "}$;\5
$\\{incr}(\\{limit})$;\6
\&{end};\2\6
$\\{decr}(\\{selector})$;\C{inhibit terminal output temporarily}\6
\&{for} $\|k\K\\{start}\mathrel{\&{to}}\\{limit}-1$ \1\&{do}\6
\&{begin} \37$\\{print\_char}(\\{buffer}[\|k])$;\5
$\\{pto\_chr}(\\{xchr}[\\{buffer}[\|k]])$;\6
\&{end};\2\6
$\\{print}(\.{"=>"})$;\5
$\\{first}\K\\{start}$;\6
\&{if} $\R\\{input\_ln}(\\{term\_in},\39\\{true})$ \1\&{then}\5
$\\{fatal\_error}(\.{"End\ of\ file\ on\ the\ terminal!"})$;\2\6
\&{if} $\\{last}>\\{first}$ \1\&{then}\6
\&{for} $\|k\K\\{first}\mathrel{\&{to}}\\{last}-1$ \1\&{do}\5
$\\{print\_char}(\\{buffer}[\|k])$;\2\2\6
$\\{limit}\K\\{last}$;\5
\\{print\_ln};\5
$\\{incr}(\\{selector})$;\6
\&{end};\2\2\2\6
\&{end};\par
\fi

\M364. Since \\{get\_next} is used so frequently in \TeX, it is convenient
to define three related procedures that do a little more:

\yskip\hang\\{get\_token} not only sets \\{cur\_cmd} and \\{cur\_chr}, it
also sets \\{cur\_tok}, a packed halfword version of the current token.

\yskip\hang\\{get\_x\_token}, meaning ``get an expanded token,'' is like
\\{get\_token}, but if the current token turns out to be a user-defined
control sequence (i.e., a macro call), or a conditional,
or something like \.{\\topmark} or \.{\\expandafter} or \.{\\csname},
it is eliminated from the input by beginning the expansion of the macro
or the evaluation of the conditional.

\yskip\hang\\{x\_token} is like \\{get\_x\_token} except that it assumes that
\\{get\_next} has already been called.

\yskip\noindent
In fact, these three procedures account for {\sl all\/} uses of \\{get\_next},
except for two places in the ``inner loop'' when \\{cur\_tok} need not be set,
and except when the arguments to \.{\\ifx} are being scanned.

\fi

\M365. No new control sequences will be defined except during a call of
\\{get\_token}, or when \.{\\csname} compresses a token list, because
\\{no\_new\_control\_sequence} is always \\{true} at other times.

\Y\P\4\&{procedure}\1\  \37\\{get\_token};\C{sets \\{cur\_cmd}, \\{cur\_chr}, %
\\{cur\_tok}}\2\6
\&{begin} \37$\\{no\_new\_control\_sequence}\K\\{false}$;\5
\\{get\_next};\5
$\\{no\_new\_control\_sequence}\K\\{true}$;\6
\&{if} $\\{cur\_cs}=0$ \1\&{then}\5
$\\{cur\_tok}\K(\\{cur\_cmd}\ast\O{400})+\\{cur\_chr}$\6
\4\&{else} $\\{cur\_tok}\K\\{cs\_token\_flag}+\\{cur\_cs}$;\2\6
\&{end};\par
\fi

\N366\*.  \[25] Expanding the next token.
Only a dozen or so command codes $>\\{max\_command}$ can possibly be returned
by
\\{get\_next}; in increasing order, they are \\{undefined\_cs}, \\{expand%
\_after},
\\{no\_expand}, \\{input}, \\{if\_test}, \\{fi\_or\_else}, \\{cs\_name}, %
\\{convert}, \\{the},
\\{top\_bot\_mark}, \\{call}, \\{long\_call}, \\{outer\_call}, \\{long\_outer%
\_call}, and
\\{end\_template}.

The \\{expand} subroutine is used when $\\{cur\_cmd}>\\{max\_command}$. It
removes a
``call'' or a conditional or one of the other special operations just
listed.  It follows that \\{expand} might invoke itself recursively. In all
cases, \\{expand} destroys the current token, but it sets things up so that
the next \\{get\_next} will deliver the appropriate next token. The value of
\\{cur\_tok} need not be known when \\{expand} is called.

Since several of the basic scanning routines communicate via global variables,
their values are saved as local variables of \\{expand} so that
recursive calls don't invalidate them.

\Y\P\hbox{\4}\X389:Declare the procedure called \\{macro\_call}\X\6
\hbox{\4}\X379:Declare the procedure called \\{insert\_relax}\X\6
\4\&{procedure}\1\  \37\\{pass\_text};\5
\\{forward}; \hbox{\2} \6
\4\&{procedure}\1\  \37\\{start\_input};\5
\\{forward}; \hbox{\2} \6
\4\&{procedure}\1\  \37\\{conditional};\5
\\{forward}; \hbox{\2} \6
\4\&{procedure}\1\  \37\\{get\_x\_token};\5
\\{forward}; \hbox{\2} \6
\4\&{procedure}\1\  \37\\{conv\_toks};\5
\\{forward}; \hbox{\2} \6
\4\&{procedure}\1\  \37\\{ins\_the\_toks};\5
\\{forward}; \hbox{\2} \6
\4\&{procedure}\1\  \37\\{expand};\6
\4\&{var} \37\|t: \37\\{halfword};\C{token that is being ``expanded after''}\6
$\|p,\39\|q,\39\|r$: \37\\{pointer};\C{for list manipulation}\6
\|j: \37$0\to\\{buf\_size}$;\C{index into \\{buffer}}\6
\\{cv\_backup}: \37\\{integer};\C{to save the global quantity \\{cur\_val}}\6
$\\{cvl\_backup},\39\\{radix\_backup}$: \37\\{small\_number};\C{to save \\{cur%
\_val\_level} and \\{radix}}\6
\\{backup\_backup}: \37\\{pointer};\C{to save $\\{link}(\\{backup\_head})$}\6
\\{save\_scanner\_status}: \37\\{small\_number};\C{temporary storage of %
\\{scanner\_status}}\2\6
\&{begin} \37$\\{cv\_backup}\K\\{cur\_val}$;\5
$\\{cvl\_backup}\K\\{cur\_val\_level}$;\5
$\\{radix\_backup}\K\\{radix}$;\5
$\\{incr}(\\{trace\_depth})$;\6
\&{if} $\\{tracing\_stats}>2$ \1\&{then}\5
$\\{print}(\.{"\ <x"})$;\2\6
$\\{backup\_backup}\K\\{link}(\\{backup\_head})$;\6
\&{if} $\\{cur\_cmd}<\\{call}$ \1\&{then}\5
\X367:Expand a nonmacro\X\6
\4\&{else} \&{if} $\\{cur\_cmd}<\\{end\_template}$ \1\&{then}\5
\\{macro\_call}\6
\4\&{else} \X375:Insert a \\{frozen\_endv} token\X;\2\2\6
$\\{cur\_val}\K\\{cv\_backup}$;\5
$\\{cur\_val\_level}\K\\{cvl\_backup}$;\5
$\\{radix}\K\\{radix\_backup}$;\5
$\\{link}(\\{backup\_head})\K\\{backup\_backup}$;\5
$\\{decr}(\\{trace\_depth})$;\6
\&{if} $\\{tracing\_stats}>2$ \1\&{then}\5
$\\{print\_char}(\.{">"})$;\2\6
\&{end};\par
\fi

\M367. \P$\X367:Expand a nonmacro\X\S$\6
\&{begin} \37\&{if} $\\{tracing\_commands}>1$ \1\&{then}\5
\\{show\_cur\_cmd\_chr};\2\6
\&{case} $\\{cur\_cmd}$ \1\&{of}\6
\4\\{top\_bot\_mark}: \37\X386:Insert the \(a)appropriate mark text into the
scanner\X;\6
\4\\{expand\_after}: \37\X368:Expand the token after the next token\X;\6
\4\\{no\_expand}: \37\X369:Suppress expansion of the next token\X;\6
\4\\{cs\_name}: \37\X372:Manufacture a control sequence name\X;\6
\4\\{convert}: \37\\{conv\_toks};\C{this procedure is discussed in Part 27
below}\6
\4\\{the}: \37\\{ins\_the\_toks};\C{this procedure is discussed in Part 27
below}\6
\4\\{if\_test}: \37\\{conditional};\C{this procedure is discussed in Part 28
below}\6
\4\\{fi\_or\_else}: \37\X510:Terminate the current conditional and skip to \.{%
\\fi}\X;\6
\4\\{input}: \37\X378:Initiate or terminate input from a file\X;\6
\4\&{othercases} \37\X370:Complain about an undefined macro\X\2\6
\&{endcases};\6
\&{end}\par
\U section~366\*.\fi

\M368. It takes only a little shuffling to do what \TeX\ calls \.{%
\\expandafter}.

\Y\P$\4\X368:Expand the token after the next token\X\S$\6
\&{begin} \37\\{get\_token};\5
$\|t\K\\{cur\_tok}$;\5
\\{get\_token};\6
\&{if} $\\{cur\_cmd}>\\{max\_command}$ \1\&{then}\5
\\{expand}\ \&{else} \\{back\_input};\2\6
$\\{cur\_tok}\K\|t$;\5
\\{back\_input};\6
\&{end}\par
\U section~367.\fi

\M369. The implementation of \.{\\noexpand} is a bit trickier, because it is
necessary to insert a special `\\{dont\_expand}' marker into \TeX's reading
mechanism.  This special marker is processed by \\{get\_next}, but it does
not slow down the inner loop.

Since \.{\\outer} macros might arise here, we must also
clear the \\{scanner\_status} temporarily.

\Y\P$\4\X369:Suppress expansion of the next token\X\S$\6
\&{begin} \37$\\{save\_scanner\_status}\K\\{scanner\_status}$;\5
$\\{scanner\_status}\K\\{normal}$;\5
\\{get\_token};\5
$\\{scanner\_status}\K\\{save\_scanner\_status}$;\5
$\|t\K\\{cur\_tok}$;\5
\\{back\_input};\C{now \\{start} and \\{loc} point to the backed-up token \|t}\6
\&{if} $\|t\G\\{cs\_token\_flag}$ \1\&{then}\6
\&{begin} \37$\|p\K\\{get\_avail}$;\5
$\\{info}(\|p)\K\\{cs\_token\_flag}+\\{frozen\_dont\_expand}$;\5
$\\{link}(\|p)\K\\{loc}$;\5
$\\{start}\K\|p$;\5
$\\{loc}\K\|p$;\6
\&{end};\2\6
\&{end}\par
\U section~367.\fi

\M370. \P$\X370:Complain about an undefined macro\X\S$\6
\&{begin} \37$\\{print\_err}(\.{"Undefined\ control\ sequence"})$;\5
$\\{help5}(\.{"The\ control\ sequence\ at\ the\ end\ of\ the\ top\ line"})$\6
$(\.{"of\ your\ error\ message\ was\ never\ \\def\'ed.\ If\ you\ have"})$\6
$(\.{"misspelled\ it\ (e.g.,\ \`\\hobx\'),\ type\ \`I\'\ and\ the\ correct"})$\6
$(\.{"spelling\ (e.g.,\ \`I\\hbox\').\ Otherwise\ just\ continue,"})$\6
$(\.{"and\ I\'ll\ forget\ about\ whatever\ was\ undefined."})$;\5
\\{error};\6
\&{end}\par
\U section~367.\fi

\M371. The \\{expand} procedure and some other routines that construct token
lists find it convenient to use the following macros, which are valid only if
the variables \|p and \|q are reserved for token-list building.

\Y\P\D \37$\\{store\_new\_token}(\#)\S$\1\6
\&{begin} \37$\|q\K\\{get\_avail}$;\5
$\\{link}(\|p)\K\|q$;\5
$\\{info}(\|q)\K\#$;\5
$\|p\K\|q$;\C{$\\{link}(\|p)$ is \\{null}}\6
\&{end}\2\par
\P\D \37$\\{fast\_store\_new\_token}(\#)\S$\1\6
\&{begin} \37$\\{fast\_get\_avail}(\|q)$;\5
$\\{link}(\|p)\K\|q$;\5
$\\{info}(\|q)\K\#$;\5
$\|p\K\|q$;\C{$\\{link}(\|p)$ is \\{null}}\6
\&{end}\2\par
\fi

\M372. \P$\X372:Manufacture a control sequence name\X\S$\6
\&{begin} \37$\|r\K\\{get\_avail}$;\5
$\|p\K\|r$;\C{head of the list of characters}\6
\1\&{repeat} \37\\{get\_x\_token};\6
\&{if} $\\{cur\_cs}=0$ \1\&{then}\5
$\\{store\_new\_token}(\\{cur\_tok})$;\2\6
\4\&{until}\5
$\\{cur\_cs}\I0$;\2\6
\&{if} $\\{cur\_cmd}\I\\{end\_cs\_name}$ \1\&{then}\5
\X373:Complain about missing \.{\\endcsname}\X;\2\6
\X374:Look up the characters of list \|r in the hash table, and set \\{cur\_cs}%
\X;\6
$\\{flush\_list}(\|r)$;\6
\&{if} $\\{eq\_type}(\\{cur\_cs})=\\{undefined\_cs}$ \1\&{then}\6
\&{begin} \37$\\{eqtb}[\\{cur\_cs}]\K\\{eqtb}[\\{frozen\_relax}]$;\6
\&{end};\C{the control sequence will now match `\.{\\relax}'}\2\6
$\\{cur\_tok}\K\\{cur\_cs}+\\{cs\_token\_flag}$;\5
\\{back\_input};\6
\&{end}\par
\U section~367.\fi

\M373. \P$\X373:Complain about missing \.{\\endcsname}\X\S$\6
\&{begin} \37$\\{print\_err}(\.{"Missing\ "})$;\5
$\\{print\_esc}(\.{"endcsname"})$;\5
$\\{print}(\.{"\ inserted"})$;\5
$\\{help2}(\.{"The\ control\ sequence\ marked\ <to\ be\ read\ again>\
should"})$\6
$(\.{"not\ appear\ between\ \\csname\ and\ \\endcsname."})$;\5
\\{back\_error};\6
\&{end}\par
\U section~372.\fi

\M374. \P$\X374:Look up the characters of list \|r in the hash table, and set %
\\{cur\_cs}\X\S$\6
$\|j\K\\{first}$;\5
$\|p\K\\{link}(\|r)$;\6
\&{while} $\|p\I\\{null}$ \1\&{do}\6
\&{begin} \37\&{if} $\|j\G\\{max\_buf\_stack}$ \1\&{then}\6
\&{begin} \37$\\{max\_buf\_stack}\K\|j+1$;\6
\&{if} $\\{max\_buf\_stack}=\\{buf\_size}$ \1\&{then}\5
$\\{overflow}(\.{"buffer\ size"},\39\\{buf\_size})$;\2\6
\&{end};\2\6
$\\{buffer}[\|j]\K\\{info}(\|p)\mathbin{\&{mod}}\O{400}$;\5
$\\{incr}(\|j)$;\5
$\|p\K\\{link}(\|p)$;\6
\&{end};\2\6
\&{if} $\|j>\\{first}+1$ \1\&{then}\6
\&{begin} \37$\\{no\_new\_control\_sequence}\K\\{false}$;\5
$\\{cur\_cs}\K\\{id\_lookup}(\\{first},\39\|j-\\{first})$;\5
$\\{no\_new\_control\_sequence}\K\\{true}$;\6
\&{end}\6
\4\&{else} \&{if} $\|j=\\{first}$ \1\&{then}\5
$\\{cur\_cs}\K\\{null\_cs}$\C{the list is empty}\6
\4\&{else} $\\{cur\_cs}\K\\{single\_base}+\\{buffer}[\\{first}]$\C{the list has
length one}\2\2\par
\U section~372.\fi

\M375. An \\{end\_template} command is effectively changed to an \\{endv}
command
by the following code. (The reason for this is discussed below; the
\\{frozen\_end\_template} at the end of the template has passed the
\\{check\_outer\_validity} test, so its mission of error detection has been
accomplished.)

\Y\P$\4\X375:Insert a \\{frozen\_endv} token\X\S$\6
\&{begin} \37$\\{cur\_tok}\K\\{cs\_token\_flag}+\\{frozen\_endv}$;\5
\\{back\_input};\6
\&{end}\par
\U section~366\*.\fi

\M376. The processing of \.{\\input} involves the \\{start\_input} subroutine,
which will be declared later; the processing of \.{\\endinput} is trivial.

\Y\P$\4\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}\S$\6
$\\{primitive}(\.{"input"},\39\\{input},\390)$;\6
$\\{primitive}(\.{"endinput"},\39\\{input},\391)$;\par
\fi

\M377. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{input}: \37\&{if} $\\{chr\_code}=0$ \1\&{then}\5
$\\{print\_esc}(\.{"input"})$\ \&{else} $\\{print\_esc}(\.{"endinput"})$;\2\par
\fi

\M378. \P$\X378:Initiate or terminate input from a file\X\S$\6
\&{if} $\\{cur\_chr}>0$ \1\&{then}\5
$\\{force\_eof}\K\\{true}$\6
\4\&{else} \&{if} $\\{name\_in\_progress}$ \1\&{then}\5
\\{insert\_relax}\6
\4\&{else} \\{start\_input}\2\2\par
\U section~367.\fi

\M379. Sometimes the expansion looks too far ahead, so we want to insert
a harmless \.{\\relax} into the user's input.

\Y\P$\4\X379:Declare the procedure called \\{insert\_relax}\X\S$\6
\4\&{procedure}\1\  \37\\{insert\_relax};\2\6
\&{begin} \37$\\{cur\_tok}\K\\{cs\_token\_flag}+\\{cur\_cs}$;\5
\\{back\_input};\5
$\\{cur\_tok}\K\\{cs\_token\_flag}+\\{frozen\_relax}$;\5
\\{back\_input};\5
$\\{token\_type}\K\\{inserted}$;\6
\&{end};\par
\U section~366\*.\fi

\M380. Here is a recursive procedure that is \TeX's usual way to get the
next token of input. It has been slightly optimized to take account of
common cases.

\Y\P\4\&{procedure}\1\  \37\\{get\_x\_token};\C{sets \\{cur\_cmd}, \\{cur%
\_chr}, \\{cur\_tok}, 	and expands macros}\6
\4\&{label} \37$\\{restart},\39\\{done}$;\2\6
\&{begin} \37\\{restart}: \37\\{get\_next};\6
\&{if} $\\{cur\_cmd}\L\\{max\_command}$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
\&{if} $\\{cur\_cmd}\G\\{call}$ \1\&{then}\6
\&{if} $\\{cur\_cmd}<\\{end\_template}$ \1\&{then}\5
\\{macro\_call}\6
\4\&{else} \&{begin} \37$\\{cur\_cs}\K\\{frozen\_endv}$;\5
$\\{cur\_cmd}\K\\{endv}$;\5
\&{goto} \37\\{done};\C{$\\{cur\_chr}=\\{null\_list}$}\6
\&{end}\2\6
\4\&{else} \\{expand};\2\6
\&{goto} \37\\{restart};\6
\4\\{done}: \37\&{if} $\\{cur\_cs}=0$ \1\&{then}\5
$\\{cur\_tok}\K(\\{cur\_cmd}\ast\O{400})+\\{cur\_chr}$\6
\4\&{else} $\\{cur\_tok}\K\\{cs\_token\_flag}+\\{cur\_cs}$;\2\6
\&{end};\par
\fi

\M381. The \\{get\_x\_token} procedure is equivalent to two consecutive
procedure calls: \\{get\_next}; \\{x\_token}.

\Y\P\4\&{procedure}\1\  \37\\{x\_token};\C{\\{get\_x\_token} without the
initial \\{get\_next}}\2\6
\&{begin} \37\&{while} $\\{cur\_cmd}>\\{max\_command}$ \1\&{do}\6
\&{begin} \37\\{expand};\5
\\{get\_next};\6
\&{end};\2\6
\&{if} $\\{cur\_cs}=0$ \1\&{then}\5
$\\{cur\_tok}\K(\\{cur\_cmd}\ast\O{400})+\\{cur\_chr}$\6
\4\&{else} $\\{cur\_tok}\K\\{cs\_token\_flag}+\\{cur\_cs}$;\2\6
\&{end};\par
\fi

\M382. A control sequence that has been \.{\\def}'ed by the user is expanded by
\TeX's \\{macro\_call} procedure.

Before we get into the details of \\{macro\_call}, however, let's consider the
treatment of primitives like \.{\\topmark}, since they are essentially
macros without parameters. The token lists for such marks are kept in a
global array of five pointers; we refer to the individual entries of this
array by symbolic names \\{top\_mark}, etc. The value of \\{top\_mark} is
either
\\{null} or a pointer to the reference count of a token list.

\Y\P\D \37$\\{top\_mark\_code}=0$\C{the mark in effect at the previous page
break}\par
\P\D \37$\\{first\_mark\_code}=1$\C{the first mark between \\{top\_mark} and %
\\{bot\_mark}}\par
\P\D \37$\\{bot\_mark\_code}=2$\C{the mark in effect at the current page break}%
\par
\P\D \37$\\{split\_first\_mark\_code}=3$\C{the first mark found by \.{%
\\vsplit}}\par
\P\D \37$\\{split\_bot\_mark\_code}=4$\C{the last mark found by \.{\\vsplit}}%
\par
\P\D \37$\\{top\_mark}\S\\{cur\_mark}[\\{top\_mark\_code}]$\par
\P\D \37$\\{first\_mark}\S\\{cur\_mark}[\\{first\_mark\_code}]$\par
\P\D \37$\\{bot\_mark}\S\\{cur\_mark}[\\{bot\_mark\_code}]$\par
\P\D \37$\\{split\_first\_mark}\S\\{cur\_mark}[\\{split\_first\_mark\_code}]$%
\par
\P\D \37$\\{split\_bot\_mark}\S\\{cur\_mark}[\\{split\_bot\_mark\_code}]$\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{cur\_mark}: \37\&{array} $[\\{top\_mark\_code}\to\\{split\_bot\_mark%
\_code}]$ \1\&{of}\5
\\{pointer};\C{token lists for marks}\2\par
\fi

\M383. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{top\_mark}\K\\{null}$;\5
$\\{first\_mark}\K\\{null}$;\5
$\\{bot\_mark}\K\\{null}$;\5
$\\{split\_first\_mark}\K\\{null}$;\5
$\\{split\_bot\_mark}\K\\{null}$;\par
\fi

\M384. \P$\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}%
\S$\6
$\\{primitive}(\.{"topmark"},\39\\{top\_bot\_mark},\39\\{top\_mark\_code})$;\5
$\\{primitive}(\.{"firstmark"},\39\\{top\_bot\_mark},\39\\{first\_mark%
\_code})$;\5
$\\{primitive}(\.{"botmark"},\39\\{top\_bot\_mark},\39\\{bot\_mark\_code})$;\5
$\\{primitive}(\.{"splitfirstmark"},\39\\{top\_bot\_mark},\39\\{split\_first%
\_mark\_code})$;\5
$\\{primitive}(\.{"splitbotmark"},\39\\{top\_bot\_mark},\39\\{split\_bot\_mark%
\_code})$;\par
\fi

\M385. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{top\_bot\_mark}: \37\&{case} $\\{chr\_code}$ \1\&{of}\6
\4\\{first\_mark\_code}: \37$\\{print\_esc}(\.{"firstmark"})$;\6
\4\\{bot\_mark\_code}: \37$\\{print\_esc}(\.{"botmark"})$;\6
\4\\{split\_first\_mark\_code}: \37$\\{print\_esc}(\.{"splitfirstmark"})$;\6
\4\\{split\_bot\_mark\_code}: \37$\\{print\_esc}(\.{"splitbotmark"})$;\6
\4\&{othercases} \37$\\{print\_esc}(\.{"topmark"})$\2\6
\&{endcases};\par
\fi

\M386. The following code is activated when $\\{cur\_cmd}=\\{top\_bot\_mark}$
and
when \\{cur\_chr} is a code like \\{top\_mark\_code}.

\Y\P$\4\X386:Insert the \(a)appropriate mark text into the scanner\X\S$\6
\&{begin} \37\&{if} $\\{cur\_mark}[\\{cur\_chr}]\I\\{null}$ \1\&{then}\5
$\\{begin\_token\_list}(\\{cur\_mark}[\\{cur\_chr}],\39\\{mark\_text})$;\2\6
\&{end}\par
\U section~367.\fi

\M387. Now let's consider \\{macro\_call} itself, which is invoked when \TeX\
is
scanning a control sequence whose \\{cur\_cmd} is either \\{call}, \\{long%
\_call},
\\{outer\_call}, or \\{long\_outer\_call}.  The control sequence definition
appears in the token list whose reference count is in location \\{cur\_chr}
of \\{mem}.

The global variable \\{long\_state} will be set to \\{call} or to \\{long%
\_call},
depending on whether or not the control sequence disallows \.{\\par}
in its parameters. The \\{get\_next} routine will set \\{long\_state} to
\\{outer\_call} and emit \.{\\par}, if a file ends or if an \.{\\outer}
control sequence occurs in the midst of an argument.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{long\_state}: \37$\\{call}\to\\{long\_outer\_call}$;\C{governs the
acceptance of \.{\\par}}\par
\fi

\M388. The parameters, if any, must be scanned before the macro is expanded.
Parameters are token lists without reference counts. They are placed on
an auxiliary stack called \\{pstack} while they are being scanned, since
the \\{param\_stack} may be losing entries during the matching process.
(Note that \\{param\_stack} can't be gaining entries, since \\{macro\_call} is
the only routine that puts anything onto \\{param\_stack}, and it
is not recursive.)

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{pstack}: \37\&{array} $[0\to8]$ \1\&{of}\5
\\{pointer};\C{arguments supplied to a macro}\2\par
\fi

\M389. After parameter scanning is complete, the parameters are moved to the
\\{param\_stack}. Then the macro body is fed to the scanner; in other words,
\\{macro\_call} places the defined text of the control sequence at the
top of\/ \TeX's input stack, so that \\{get\_next} will proceed to read it
next.

The global variable \\{cur\_cs} contains the \\{eqtb} address of the control
sequence
being expanded, when \\{macro\_call} begins. If this control sequence has not
been
declared \.{\\long}, i.e., if its command code in the \\{eq\_type} field is
not \\{long\_call} or \\{long\_outer\_call}, its parameters are not allowed to
contain
the control sequence \.{\\par}. If an illegal \.{\\par} appears, the macro
call is aborted, and the \.{\\par} will be rescanned.

\Y\P$\4\X389:Declare the procedure called \\{macro\_call}\X\S$\6
\4\&{procedure}\1\  \37\\{macro\_call};\C{invokes a user-defined control
sequence}\6
\4\&{label} \37$\\{exit},\39\\{continue},\39\\{done},\39\\{done1},\39%
\\{found}$;\6
\4\&{var} \37\|r: \37\\{pointer};\C{current node in the macro's token list}\6
\|p: \37\\{pointer};\C{current node in parameter token list being built}\6
\|q: \37\\{pointer};\C{new node being put into the token list}\6
\|s: \37\\{pointer};\C{backup pointer for parameter matching}\6
\|t: \37\\{pointer};\C{cycle pointer for backup recovery}\6
$\|u,\39\|v$: \37\\{pointer};\C{auxiliary pointers for backup recovery}\6
\\{rbrace\_ptr}: \37\\{pointer};\C{one step before the last \\{right\_brace}
token}\6
\|n: \37\\{small\_number};\C{the number of parameters scanned}\6
\\{unbalance}: \37\\{halfword};\C{unmatched left braces in current parameter}\6
\|m: \37\\{halfword};\C{the number of tokens or groups (usually)}\6
\\{ref\_count}: \37\\{pointer};\C{start of the token list}\6
\\{save\_scanner\_status}: \37\\{small\_number};\C{\\{scanner\_status} upon
entry}\6
\\{save\_warning\_index}: \37\\{pointer};\C{\\{warning\_index} upon entry}\6
\\{match\_chr}: \37\\{ASCII\_code};\C{character used in parameter}\2\6
\&{begin} \37$\\{save\_scanner\_status}\K\\{scanner\_status}$;\5
$\\{save\_warning\_index}\K\\{warning\_index}$;\5
$\\{warning\_index}\K\\{cur\_cs}$;\5
$\\{ref\_count}\K\\{cur\_chr}$;\5
$\|r\K\\{link}(\\{ref\_count})$;\5
$\|n\K0$;\6
\&{if} $\\{tracing\_macros}>0$ \1\&{then}\5
\X401:Show the text of the macro being expanded\X;\2\6
\&{if} $\\{info}(\|r)\I\\{end\_match\_token}$ \1\&{then}\5
\X391:Scan the parameters and make $\\{link}(\|r)$ point to the macro body; but
\&{return} if an illegal \.{\\par} is detected\X;\2\6
\X390:Feed the macro body and its parameters to the scanner\X;\6
\4\\{exit}: \37$\\{scanner\_status}\K\\{save\_scanner\_status}$;\5
$\\{warning\_index}\K\\{save\_warning\_index}$;\6
\&{end};\par
\U section~366\*.\fi

\M390. Before we put a new token list on the input stack, it is wise to clean
off
all token lists that have recently been depleted. Then a user macro that ends
with a call to itself will not require unbounded stack space.

\Y\P$\4\X390:Feed the macro body and its parameters to the scanner\X\S$\6
\&{while} $(\\{state}=\\{token\_list})\W(\\{loc}=\\{null})$ \1\&{do}\5
\\{end\_token\_list};\C{conserve stack space}\2\6
$\\{begin\_token\_list}(\\{ref\_count},\39\\{macro})$;\5
$\\{name}\K\\{warning\_index}$;\5
$\\{loc}\K\\{link}(\|r)$;\6
\&{if} $\|n>0$ \1\&{then}\6
\&{begin} \37\&{if} $\\{param\_ptr}+\|n>\\{max\_param\_stack}$ \1\&{then}\6
\&{begin} \37$\\{max\_param\_stack}\K\\{param\_ptr}+\|n$;\6
\&{if} $\\{max\_param\_stack}>\\{param\_size}$ \1\&{then}\5
$\\{overflow}(\.{"parameter\ stack\ size"},\39\\{param\_size})$;\2\6
\&{end};\2\6
\&{for} $\|m\K0\mathrel{\&{to}}\|n-1$ \1\&{do}\5
$\\{param\_stack}[\\{param\_ptr}+\|m]\K\\{pstack}[\|m]$;\2\6
$\\{param\_ptr}\K\\{param\_ptr}+\|n$;\6
\&{end}\2\par
\U section~389.\fi

\M391. At this point, the reader will find it advisable to review the
explanation
of token list format that was presented earlier, since many aspects of that
format are of importance chiefly in the \\{macro\_call} routine.

The token list might begin with a string of compulsory tokens before the
first \\{match} or \\{end\_match}. In that case the macro name is supposed to
be
followed by those tokens; the following program will set $\|s=\\{null}$ to
represent this restriction. Otherwise \|s will be set to the first token of
a string that will delimit the next parameter.

\Y\P$\4\X391:Scan the parameters and make $\\{link}(\|r)$ point to the macro
body; but \&{return} if an illegal \.{\\par} is detected\X\S$\6
\&{begin} \37$\\{scanner\_status}\K\\{matching}$;\5
$\\{unbalance}\K0$;\5
$\\{long\_state}\K\\{eq\_type}(\\{cur\_cs})$;\6
\&{if} $\\{long\_state}\G\\{outer\_call}$ \1\&{then}\5
$\\{long\_state}\K\\{long\_state}-2$;\2\6
\1\&{repeat} \37\&{if} $(\\{info}(\|r)>\\{match\_token}+127)\V(\\{info}(\|r)<%
\\{match\_token})$ \1\&{then}\5
$\|s\K\\{null}$\6
\4\&{else} \&{begin} \37$\\{match\_chr}\K\\{info}(\|r)-\\{match\_token}$;\5
$\|s\K\\{link}(\|r)$;\5
$\|r\K\|s$;\5
$\|p\K\\{temp\_head}$;\5
$\\{link}(\|p)\K\\{null}$;\5
$\|m\K0$;\6
\&{end};\2\6
\X392:Scan a parameter until its delimiter string has been found; or, if $\|s=%
\\{null}$, simply scan the delimiter string\X;\6
\C{now $\\{info}(\|r)$ is a token whose command code is either \\{match} or %
\\{end\_match}}\6
\4\&{until}\5
$\\{info}(\|r)=\\{end\_match\_token}$;\2\6
\&{end}\par
\U section~389.\fi

\M392. If $\\{info}(\|r)$ is a \\{match} or \\{end\_match} command, it cannot
be equal to
any token found by \\{get\_token}. Therefore an undelimited parameter---i.e.,
a \\{match} that is immediately followed by \\{match} or \\{end\_match}---will
always fail the test `$\\{cur\_tok}=\\{info}(\|r)$' in the following algorithm.

\Y\P$\4\X392:Scan a parameter until its delimiter string has been found; or, if
$\|s=\\{null}$, simply scan the delimiter string\X\S$\6
\4\\{continue}: \37\\{get\_token};\C{set \\{cur\_tok} to the next token of
input}\6
\&{if} $\\{cur\_tok}=\\{info}(\|r)$ \1\&{then}\5
\X394:Advance \(r)\|r; \&{goto} \\{found} if the parameter delimiter has been
fully matched, otherwise \&{goto} \\{continue}\X;\2\6
\X397:Contribute the recently matched tokens to the current parameter, and %
\&{goto} \\{continue} if a partial match is still in effect; but abort if $\|s=%
\\{null}$\X;\6
\&{if} $\\{cur\_tok}=\\{par\_token}$ \1\&{then}\6
\&{if} $\\{long\_state}\I\\{long\_call}$ \1\&{then}\5
\X396:Report a runaway argument and abort\X;\2\2\6
\&{if} $\\{cur\_tok}<\\{right\_brace\_limit}$ \1\&{then}\6
\&{if} $\\{cur\_tok}<\\{left\_brace\_limit}$ \1\&{then}\5
\X399:Contribute an entire group to the current parameter\X\6
\4\&{else} \X395:Report an extra right brace and \&{goto} \\{continue}\X\2\6
\4\&{else} \X393:Store the current token, but \&{goto} \\{continue} if it is a
blank space that would become an undelimited parameter\X;\2\6
$\\{incr}(\|m)$;\6
\&{if} $\\{info}(\|r)>\\{end\_match\_token}$ \1\&{then}\5
\&{goto} \37\\{continue};\2\6
\&{if} $\\{info}(\|r)<\\{match\_token}$ \1\&{then}\5
\&{goto} \37\\{continue};\2\6
\4\\{found}: \37\&{if} $\|s\I\\{null}$ \1\&{then}\5
\X400:Tidy up the parameter just scanned, and tuck it away\X\2\par
\U section~391.\fi

\M393. \P$\X393:Store the current token, but \&{goto} \\{continue} if it is a
blank space that would become an undelimited parameter\X\S$\6
\&{begin} \37\&{if} $\\{cur\_tok}=\\{space\_token}$ \1\&{then}\6
\&{if} $\\{info}(\|r)\L\\{end\_match\_token}$ \1\&{then}\6
\&{if} $\\{info}(\|r)\G\\{match\_token}$ \1\&{then}\5
\&{goto} \37\\{continue};\2\2\2\6
$\\{store\_new\_token}(\\{cur\_tok})$;\6
\&{end}\par
\U section~392.\fi

\M394. A slightly subtle point arises here: When the parameter delimiter ends
with `\.{\#\{}', the token list will have a left brace both before and
after the \\{end\_match}\kern-.4pt. Only one of these should affect the
\\{align\_state}, but both will be scanned, so we must make a correction.

\Y\P$\4\X394:Advance \(r)\|r; \&{goto} \\{found} if the parameter delimiter has
been fully matched, otherwise \&{goto} \\{continue}\X\S$\6
\&{begin} \37$\|r\K\\{link}(\|r)$;\6
\&{if} $(\\{info}(\|r)\G\\{match\_token})\W(\\{info}(\|r)\L\\{end\_match%
\_token})$ \1\&{then}\6
\&{begin} \37\&{if} $\\{cur\_tok}<\\{left\_brace\_limit}$ \1\&{then}\5
$\\{decr}(\\{align\_state})$;\2\6
\&{goto} \37\\{found};\6
\&{end}\6
\4\&{else} \&{goto} \37\\{continue};\2\6
\&{end}\par
\U section~392.\fi

\M395. \P$\X395:Report an extra right brace and \&{goto} \\{continue}\X\S$\6
\&{begin} \37\\{back\_input};\5
$\\{print\_err}(\.{"Argument\ of\ "})$;\5
$\\{sprint\_cs}(\\{warning\_index})$;\5
$\\{print}(\.{"\ has\ an\ extra\ \}"})$;\5
$\\{help6}(\.{"I\'ve\ run\ across\ a\ \`\}\'\ that\ doesn\'t\ seem\ to\ match\
anything."})$\6
$(\.{"For\ example,\ \`\\def\\a\#1\{...\}\'\ and\ \`\\a\}\'\ would\ produce"})$%
\6
$(\.{"this\ error.\ If\ you\ simply\ proceed\ now,\ the\ \`\\par\'\ that"})$\6
$(\.{"I\'ve\ just\ inserted\ will\ cause\ me\ to\ report\ a\ runaway"})$\6
$(\.{"argument\ that\ might\ be\ the\ root\ of\ the\ problem.\ But\ if"})$\6
$(\.{"your\ \`\}\'\ was\ spurious,\ just\ type\ \`2\'\ and\ it\ will\ go\
away."})$;\5
$\\{incr}(\\{align\_state})$;\5
$\\{long\_state}\K\\{call}$;\5
$\\{cur\_tok}\K\\{par\_token}$;\5
\\{ins\_error};\6
\&{end}\par
\U section~392.\fi

\M396. If $\\{long\_state}=\\{outer\_call}$, a runaway argument has already
been reported.

\Y\P$\4\X396:Report a runaway argument and abort\X\S$\6
\&{begin} \37\&{if} $\\{long\_state}=\\{call}$ \1\&{then}\6
\&{begin} \37\\{runaway};\5
$\\{print\_err}(\.{"Paragraph\ ended\ before\ "})$;\5
$\\{sprint\_cs}(\\{warning\_index})$;\5
$\\{print}(\.{"\ was\ complete"})$;\5
$\\{help3}(\.{"I\ suspect\ you\'ve\ forgotten\ a\ \`\}\',\ causing\ me\ to\
apply\ this"})$\6
$(\.{"control\ sequence\ to\ too\ much\ text.\ How\ can\ we\ recover?"})$\6
$(\.{"My\ plan\ is\ to\ forget\ the\ whole\ thing\ and\ hope\ for\ the\
best."})$;\5
\\{back\_error};\6
\&{end};\2\6
$\\{pstack}[\|n]\K\\{link}(\\{temp\_head})$;\5
$\\{align\_state}\K\\{align\_state}-\\{unbalance}$;\6
\&{for} $\|m\K0\mathrel{\&{to}}\|n$ \1\&{do}\5
$\\{flush\_list}(\\{pstack}[\|m])$;\2\6
\&{return};\6
\&{end}\par
\U sections~392 and~399.\fi

\M397. When the following code becomes active, we have matched tokens from \|s
to
the predecessor of \|r, and we have found that $\\{cur\_tok}\I\\{info}(\|r)$.
An
interesting situation now presents itself: If the parameter is to be
delimited by a string such as `\.{ab}', and if we have scanned `\.{aa}',
we want to contribute one `\.a' to the current parameter and resume
looking for a `\.b'. The program must account for such partial matches and
for others that can be quite complex.  But most of the time we have $\|s=\|r$
and nothing needs to be done.

Incidentally, it is possible for \.{\\par} tokens to sneak in to certain
parameters of non-\.{\\long} macros. For example, consider a case like
`\.{\\def\\a\#1\\par!\{...\}}' where the first \.{\\par} is not followed
by an exclamation point. In such situations it does not seem appropriate
to prohibit the \.{\\par}, so \TeX\ keeps quiet about this bending of
the rules.

\Y\P$\4\X397:Contribute the recently matched tokens to the current parameter,
and \&{goto} \\{continue} if a partial match is still in effect; but abort if $%
\|s=\\{null}$\X\S$\6
\&{if} $\|s\I\|r$ \1\&{then}\6
\&{if} $\|s=\\{null}$ \1\&{then}\5
\X398:Report an improper use of the macro and abort\X\6
\4\&{else} \&{begin} \37$\|t\K\|s$;\6
\1\&{repeat} \37$\\{store\_new\_token}(\\{info}(\|t))$;\5
$\\{incr}(\|m)$;\5
$\|u\K\\{link}(\|t)$;\5
$\|v\K\|s$;\6
\~ \1\&{loop}\ \&{begin} \37\&{if} $\|u=\|r$ \1\&{then}\6
\&{if} $\\{cur\_tok}\I\\{info}(\|v)$ \1\&{then}\5
\&{goto} \37\\{done}\6
\4\&{else} \&{begin} \37$\|r\K\\{link}(\|v)$;\5
\&{goto} \37\\{continue};\6
\&{end};\2\2\6
\&{if} $\\{info}(\|u)\I\\{info}(\|v)$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
$\|u\K\\{link}(\|u)$;\5
$\|v\K\\{link}(\|v)$;\6
\&{end};\2\6
\4\\{done}: \37$\|t\K\\{link}(\|t)$;\6
\4\&{until}\5
$\|t=\|r$;\2\6
$\|r\K\|s$;\C{at this point, no tokens are recently matched}\6
\&{end}\2\2\par
\U section~392.\fi

\M398. \P$\X398:Report an improper use of the macro and abort\X\S$\6
\&{begin} \37$\\{print\_err}(\.{"Use\ of\ "})$;\5
$\\{sprint\_cs}(\\{warning\_index})$;\5
$\\{print}(\.{"\ doesn\'t\ match\ its\ definition"})$;\5
$\\{help4}(\.{"If\ you\ say,\ e.g.,\ \`\\def\\a1\{...\}\',\ then\ you\ must\
always"})$\6
$(\.{"put\ \`1\'\ after\ \`\\a\',\ since\ control\ sequence\ names\ are"})$\6
$(\.{"made\ up\ of\ letters\ only.\ The\ macro\ here\ has\ not\ been"})$\6
$(\.{"followed\ by\ the\ required\ stuff,\ so\ I\'m\ ignoring\ it."})$;\5
\\{error};\5
\&{return};\6
\&{end}\par
\U section~397.\fi

\M399. \P$\X399:Contribute an entire group to the current parameter\X\S$\6
\&{begin} \37$\\{unbalance}\K1$;\6
\~ \1\&{loop}\ \&{begin} \37$\\{fast\_store\_new\_token}(\\{cur\_tok})$;\5
\\{get\_token};\6
\&{if} $\\{cur\_tok}=\\{par\_token}$ \1\&{then}\6
\&{if} $\\{long\_state}\I\\{long\_call}$ \1\&{then}\5
\X396:Report a runaway argument and abort\X;\2\2\6
\&{if} $\\{cur\_tok}<\\{right\_brace\_limit}$ \1\&{then}\6
\&{if} $\\{cur\_tok}<\\{left\_brace\_limit}$ \1\&{then}\5
$\\{incr}(\\{unbalance})$\6
\4\&{else} \&{begin} \37$\\{decr}(\\{unbalance})$;\6
\&{if} $\\{unbalance}=0$ \1\&{then}\5
\&{goto} \37\\{done1};\2\6
\&{end};\2\2\6
\&{end};\2\6
\4\\{done1}: \37$\\{rbrace\_ptr}\K\|p$;\5
$\\{store\_new\_token}(\\{cur\_tok})$;\6
\&{end}\par
\U section~392.\fi

\M400. If the parameter consists of a single group enclosed in braces, we must
strip off the enclosing braces. That's why \\{rbrace\_ptr} was introduced.

\Y\P$\4\X400:Tidy up the parameter just scanned, and tuck it away\X\S$\6
\&{begin} \37\&{if} $(\|m=1)\W(\\{info}(\|p)<\\{right\_brace\_limit})\W(\|p\I%
\\{temp\_head})$ \1\&{then}\6
\&{begin} \37$\\{link}(\\{rbrace\_ptr})\K\\{null}$;\5
$\\{free\_avail}(\|p)$;\5
$\|p\K\\{link}(\\{temp\_head})$;\5
$\\{pstack}[\|n]\K\\{link}(\|p)$;\5
$\\{free\_avail}(\|p)$;\6
\&{end}\6
\4\&{else} $\\{pstack}[\|n]\K\\{link}(\\{temp\_head})$;\2\6
$\\{incr}(\|n)$;\6
\&{if} $\\{tracing\_macros}>0$ \1\&{then}\6
\&{begin} \37\\{begin\_diagnostic};\5
$\\{print\_nl}(\\{match\_chr})$;\5
$\\{print\_int}(\|n)$;\5
$\\{print}(\.{"<-"})$;\5
$\\{show\_token\_list}(\\{pstack}[\|n-1],\39\\{null},\391000)$;\5
$\\{end\_diagnostic}(\\{false})$;\6
\&{end};\2\6
\&{end}\par
\U section~392.\fi

\M401. \P$\X401:Show the text of the macro being expanded\X\S$\6
\&{begin} \37\\{begin\_diagnostic};\5
\\{print\_ln};\5
$\\{print\_cs}(\\{warning\_index})$;\5
$\\{token\_show}(\\{ref\_count})$;\5
$\\{end\_diagnostic}(\\{false})$;\6
\&{end}\par
\U section~389.\fi

\N402.  \[26] Basic scanning subroutines.
Let's turn now to some procedures that \TeX\ calls upon frequently to digest
certain kinds of patterns in the input. Most of these are quite simple;
some are quite elaborate. Almost all of the routines call \\{get\_x\_token},
which can cause them to be invoked recursively.

\fi

\M403. The \\{scan\_left\_brace} routine is called when a left brace is
supposed to be
the next non-blank token. (The term ``left brace'' means, more precisely,
a character whose catcode is \\{left\_brace}.) \TeX\ allows \.{\\relax} to
appear before the \\{left\_brace}.

\Y\P\4\&{procedure}\1\  \37\\{scan\_left\_brace};\C{reads a mandatory \\{left%
\_brace}}\2\6
\&{begin} \37\X404:Get the next non-blank non-relax non-call token\X;\6
\&{if} $\\{cur\_cmd}\I\\{left\_brace}$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Missing\ \{\ inserted"})$;\5
$\\{help4}(\.{"A\ left\ brace\ was\ mandatory\ here,\ so\ I\'ve\ put\ one\
in."})$\6
$(\.{"You\ might\ want\ to\ delete\ and/or\ insert\ some\ corrections"})$\6
$(\.{"so\ that\ I\ will\ find\ a\ matching\ right\ brace\ soon."})$\6
$(\.{"(If\ you\'re\ confused\ by\ all\ this,\ try\ typing\ \`I\}\'\ now.)"})$;\5
\\{back\_error};\5
$\\{cur\_tok}\K\\{left\_brace\_token}+\.{"\{"}$;\5
$\\{cur\_cmd}\K\\{left\_brace}$;\5
$\\{cur\_chr}\K\.{"\{"}$;\5
$\\{incr}(\\{align\_state})$;\6
\&{end};\2\6
\&{end};\par
\fi

\M404. \P$\X404:Get the next non-blank non-relax non-call token\X\S$\6
\1\&{repeat} \37\\{get\_x\_token};\6
\4\&{until}\5
$(\\{cur\_cmd}\I\\{spacer})\W(\\{cur\_cmd}\I\\{relax})$\2\par
\U sections~403, 1078, 1084, 1151, 1160, 1211, 1226, and~1270.\fi

\M405. The \\{scan\_optional\_equals} routine looks for an optional `\.=' sign
preceded
by optional spaces; `\.{\\relax}' is not ignored here.

\Y\P\4\&{procedure}\1\  \37\\{scan\_optional\_equals};\2\6
\&{begin} \37\X406:Get the next non-blank non-call token\X;\6
\&{if} $\\{cur\_tok}\I\\{other\_token}+\.{"="}$ \1\&{then}\5
\\{back\_input};\2\6
\&{end};\par
\fi

\M406. \P$\X406:Get the next non-blank non-call token\X\S$\6
\1\&{repeat} \37\\{get\_x\_token};\6
\4\&{until}\5
$\\{cur\_cmd}\I\\{spacer}$\2\par
\U sections~405, 441, 455, 503, 526, 577, 785, 791, and~1045.\fi

\M407\*. In case you are getting bored, here is a slightly less trivial
routine:
Given a string of lowercase letters, like `\.{pt}' or `\.{plus}' or
`\.{width}', the \\{scan\_keyword} routine checks to see whether the next
tokens of input match this string. The match must be exact, except that
uppercase letters will match their lowercase counterparts; uppercase
equivalents are determined by subtracting $\.{"a"}-\.{"A"}$, rather than using
the
\\{uc\_code} table, since \TeX\ uses this routine only for its own limited
set of keywords.

If a match is found, the characters are effectively removed from the input
and \\{true} is returned. Otherwise \\{false} is returned, and the input
is left essentially unchanged (except for the fact that some macros
may have been expanded, etc.).

\Y\P\4\&{function}\1\  \37$\\{scan\_keyword}(\|s:\\{str\_number})$: \37%
\\{boolean};\C{look for a given string}\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37\|p: \37\\{pointer};\C{tail of the backup list}\6
\|q: \37\\{pointer};\C{new node being added to the token list via \\{store\_new%
\_token}}\6
\|k: \37\\{pool\_pointer};\C{index into \\{str\_pool}}\2\6
\&{begin} \37$\|p\K\\{backup\_head}$;\5
$\\{link}(\|p)\K\\{null}$;\5
$\|k\K\\{str\_start}[\|s]$;\5
$\\{incr}(\\{trace\_depth})$;\6
\&{if} $\\{tracing\_stats}>2$ \1\&{then}\6
\&{begin} \37$\\{print}(\.{"\ <\'"})$;\5
$\\{print}(\|s)$;\5
$\\{print\_char}(\.{"\'"})$;\6
\&{end};\2\6
\&{while} $\|k<\\{str\_start}[\|s+1]$ \1\&{do}\6
\&{begin} \37\\{get\_x\_token};\C{recursion is possible here}\6
\&{if} $(\\{cur\_cs}=0)\W\30((\\{cur\_chr}=\\{str\_pool}[\|k])\V(\\{cur\_chr}=%
\\{str\_pool}[\|k]-\.{"a"}+\.{"A"}))$ \1\&{then}\6
\&{begin} \37$\\{store\_new\_token}(\\{cur\_tok})$;\5
$\\{incr}(\|k)$;\6
\&{end}\6
\4\&{else} \&{if} $(\\{cur\_cmd}\I\\{spacer})\V(\|p\I\\{backup\_head})$ \1%
\&{then}\6
\&{begin} \37\\{back\_input};\6
\&{if} $\|p\I\\{backup\_head}$ \1\&{then}\5
$\\{back\_list}(\\{link}(\\{backup\_head}))$;\2\6
$\\{scan\_keyword}\K\\{false}$;\5
\&{return};\6
\&{end};\2\2\6
\&{end};\2\6
$\\{flush\_list}(\\{link}(\\{backup\_head}))$;\5
$\\{scan\_keyword}\K\\{true}$;\6
\&{if} $\\{tracing\_stats}>2$ \1\&{then}\5
$\\{print\_char}(\.{"*"})$;\2\6
\4\\{exit}: \37$\\{decr}(\\{trace\_depth})$;\6
\&{if} $\\{tracing\_stats}>2$ \1\&{then}\5
$\\{print\_char}(\.{">"})$;\2\6
\&{end};\par
\fi

\M408. Here is a procedure that sounds an alarm when mu and non-mu units
are being switched.

\Y\P\4\&{procedure}\1\  \37\\{mu\_error};\2\6
\&{begin} \37$\\{print\_err}(\.{"Incompatible\ glue\ units"})$;\5
$\\{help1}(\.{"I\'m\ going\ to\ assume\ that\ 1mu=1pt\ when\ they\'re\
mixed."})$;\5
\\{error};\6
\&{end};\par
\fi

\M409. The next routine `\\{scan\_something\_internal}' is used to fetch
internal
numeric quantities like `\.{\\hsize}', and also to handle the `\.{\\the}'
when expanding constructions like `\.{\\the\\toks0}' and
`\.{\\the\\baselineskip}'. Soon we will be considering the \\{scan\_int}
procedure, which calls \\{scan\_something\_internal}; on the other hand,
\\{scan\_something\_internal} also calls \\{scan\_int}, for constructions like
`\.{\\catcode\`\\\$}' or `\.{\\fontdimen} \.3 \.{\\ff}'. So we
have to declare \\{scan\_int} as a \\{forward} procedure. A few other
procedures are also declared at this point.

\Y\P\4\&{procedure}\1\  \37\\{scan\_int};\5
\\{forward};\C{scans an integer value}\6
\hbox{\4\4}\X432:Declare procedures that scan restricted classes of integers\X\6
\hbox{\4\4}\X577:Declare procedures that scan font-related stuff\X\par
\fi

\M410. \TeX\ doesn't know exactly what to expect when \\{scan\_something%
\_internal}
begins.  For example, an integer or dimension or glue value could occur
immediately after `\.{\\hskip}'; and one can even say \.{\\the} with
respect to token lists in constructions like
`\.{\\xdef\\o\{\\the\\output\}}'.  On the other hand, only integers are
allowed after a construction like `\.{\\count}'. To handle the various
possibilities, \\{scan\_something\_internal} has a \\{level} parameter, which
tells the ``highest'' kind of quantity that \\{scan\_something\_internal} is
allowed to produce. Six levels are distinguished, namely \\{int\_val},
\\{dimen\_val}, \\{glue\_val}, \\{mu\_val}, \\{ident\_val}, and \\{tok\_val}.

The output of \\{scan\_something\_internal} (and of the other routines
\\{scan\_int}, \\{scan\_dimen}, and \\{scan\_glue} below) is put into the
global
variable \\{cur\_val}, and its level is put into \\{cur\_val\_level}. The
highest
values of \\{cur\_val\_level} are special: \\{mu\_val} is used only when
\\{cur\_val} points to something in a ``muskip'' register, or to one of the
three parameters \.{\\thinmuskip}, \.{\\midmuskip}, \.{\\thickmuskip};
\\{ident\_val} is used only when \\{cur\_val} points to a font identifier;
\\{tok\_val} is used only when \\{cur\_val} points to \\{null} or to the
reference
count of a token list. The last two cases are allowed only when
\\{scan\_something\_internal} is called with $\\{level}=\\{tok\_val}$.

If the output is glue, \\{cur\_val} will point to a glue specification, and
the reference count of that glue will have been updated to reflect this
reference; if the output is a nonempty token list, \\{cur\_val} will point to
its reference count, but in this case the count will not have been updated.
Otherwise \\{cur\_val} will contain the integer or scaled value in question.

\Y\P\D \37$\\{int\_val}=0$\C{integer values}\par
\P\D \37$\\{dimen\_val}=1$\C{dimension values}\par
\P\D \37$\\{glue\_val}=2$\C{glue specifications}\par
\P\D \37$\\{mu\_val}=3$\C{math glue specifications}\par
\P\D \37$\\{ident\_val}=4$\C{font identifier}\par
\P\D \37$\\{tok\_val}=5$\C{token lists}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{cur\_val}: \37\\{integer};\C{value returned by numeric scanners}\6
\4\\{cur\_val\_level}: \37$\\{int\_val}\to\\{tok\_val}$;\C{the ``level'' of
this value}\par
\fi

\M411. The hash table is initialized with `\.{\\count}', `\.{\\dimen}', `\.{%
\\skip}',
and `\.{\\muskip}' all having \\{register} as their command code; they are
distinguished by the \\{chr\_code}, which is either \\{int\_val}, \\{dimen%
\_val},
\\{glue\_val}, or \\{mu\_val}.

\Y\P$\4\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}\S$\6
$\\{primitive}(\.{"count"},\39\\{register},\39\\{int\_val})$;\5
$\\{primitive}(\.{"dimen"},\39\\{register},\39\\{dimen\_val})$;\5
$\\{primitive}(\.{"skip"},\39\\{register},\39\\{glue\_val})$;\5
$\\{primitive}(\.{"muskip"},\39\\{register},\39\\{mu\_val})$;\par
\fi

\M412. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{register}: \37\&{if} $\\{chr\_code}=\\{int\_val}$ \1\&{then}\5
$\\{print\_esc}(\.{"count"})$\6
\4\&{else} \&{if} $\\{chr\_code}=\\{dimen\_val}$ \1\&{then}\5
$\\{print\_esc}(\.{"dimen"})$\6
\4\&{else} \&{if} $\\{chr\_code}=\\{glue\_val}$ \1\&{then}\5
$\\{print\_esc}(\.{"skip"})$\6
\4\&{else} $\\{print\_esc}(\.{"muskip"})$;\2\2\2\par
\fi

\M413. OK, we're ready for \\{scan\_something\_internal} itself. A second
parameter,
\\{negative}, is set \\{true} if the value that is found should be negated.
It is assumed that \\{cur\_cmd} and \\{cur\_chr} represent the first token of
the internal quantity to be scanned; an error will be signalled if
$\\{cur\_cmd}<\\{min\_internal}$ or $\\{cur\_cmd}>\\{max\_internal}$.

\Y\P\D \37$\\{scanned\_result\_end}(\#)\S\\{cur\_val\_level}\K\#$;\ \&{end} \par
\P\D \37$\\{scanned\_result}(\#)\S$\ \&{begin} \37$\\{cur\_val}\K\#$;\5
\\{scanned\_result\_end}\par
\Y\P\4\&{procedure}\1\  \37$\\{scan\_something\_internal}(\\{level}:\\{small%
\_number};\,\35\\{negative}:\\{boolean})$;\C{fetch an internal parameter}\6
\4\&{var} \37\|m: \37\\{halfword};\C{\\{chr\_code} part of the operand token}\6
\|p: \37$0\to\\{nest\_size}$;\C{index into \\{nest}}\2\6
\&{begin} \37$\|m\K\\{cur\_chr}$;\6
\&{case} $\\{cur\_cmd}$ \1\&{of}\6
\4\\{def\_code}: \37\X414:Fetch a character code from some table\X;\6
\4$\\{toks\_register},\39\\{assign\_toks},\39\\{def\_family},\39\\{set\_font},%
\39\\{def\_font}$: \37\X415:Fetch a token list or font identifier, provided
that $\\{level}=\\{tok\_val}$\X;\6
\4\\{assign\_int}: \37$\\{scanned\_result}(\\{eqtb}[\|m].\\{int})(\\{int%
\_val})$;\6
\4\\{assign\_dimen}: \37$\\{scanned\_result}(\\{eqtb}[\|m].\\{sc})(\\{dimen%
\_val})$;\6
\4\\{assign\_glue}: \37$\\{scanned\_result}(\\{equiv}(\|m))(\\{glue\_val})$;\6
\4\\{assign\_mu\_glue}: \37$\\{scanned\_result}(\\{equiv}(\|m))(\\{mu\_val})$;\6
\4\\{set\_aux}: \37\X418:Fetch the \\{space\_factor} or the \\{prev\_depth}\X;\6
\4\\{set\_prev\_graf}: \37\X422:Fetch the \\{prev\_graf}\X;\6
\4\\{set\_page\_int}: \37\X419:Fetch the \\{dead\_cycles} or the \\{insert%
\_penalties}\X;\6
\4\\{set\_page\_dimen}: \37\X421:Fetch something on the \\{page\_so\_far}\X;\6
\4\\{set\_shape}: \37\X423:Fetch the \\{par\_shape} size\X;\6
\4\\{set\_box\_dimen}: \37\X420:Fetch a box dimension\X;\6
\4$\\{char\_given},\39\\{math\_given}$: \37$\\{scanned\_result}(\\{cur\_chr})(%
\\{int\_val})$;\6
\4\\{assign\_font\_dimen}: \37\X425:Fetch a font dimension\X;\6
\4\\{assign\_font\_int}: \37\X426:Fetch a font integer\X;\6
\4\\{register}: \37\X427:Fetch a register\X;\6
\4\\{last\_item}: \37\X424:Fetch an item in the current node, if appropriate\X;%
\6
\4\&{othercases} \37\X428:Complain that \.{\\the} can't do this; give zero
result\X\2\6
\&{endcases};\6
\&{while} $\\{cur\_val\_level}>\\{level}$ \1\&{do}\5
\X429:Convert \(c)\\{cur\_val} to a lower level\X;\2\6
\X430:Fix the reference count, if any, and negate \\{cur\_val} if \\{negative}%
\X;\6
\&{end};\par
\fi

\M414. \P$\X414:Fetch a character code from some table\X\S$\6
\&{begin} \37\\{scan\_seven\_bit\_int};\6
\&{if} $\|m=\\{math\_code\_base}$ \1\&{then}\5
$\\{scanned\_result}(\\{ho}(\\{math\_code}(\\{cur\_val})))(\\{int\_val})$\6
\4\&{else} \&{if} $\|m<\\{math\_code\_base}$ \1\&{then}\5
$\\{scanned\_result}(\\{equiv}(\|m+\\{cur\_val}))(\\{int\_val})$\6
\4\&{else} $\\{scanned\_result}(\\{eqtb}[\|m+\\{cur\_val}].\\{int})(\\{int%
\_val})$;\2\2\6
\&{end}\par
\U section~413.\fi

\M415. \P$\X415:Fetch a token list or font identifier, provided that $%
\\{level}=\\{tok\_val}$\X\S$\6
\&{if} $\\{level}\I\\{tok\_val}$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Missing\ number,\ treated\ as\ zero"})$;\5
$\\{help3}(\.{"A\ number\ should\ have\ been\ here;\ I\ inserted\ \`0\'."})$\6
$(\.{"(If\ you\ can\'t\ figure\ out\ why\ I\ needed\ to\ see\ a\ number,"})$\6
$(\.{"look\ up\ \`weird\ error\'\ in\ the\ index\ to\ The\ TeXbook.)"})$;\5
\\{back\_error};\5
$\\{scanned\_result}(0)(\\{dimen\_val})$;\6
\&{end}\6
\4\&{else} \&{if} $\\{cur\_cmd}\L\\{assign\_toks}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{cur\_cmd}<\\{assign\_toks}$ \1\&{then}\C{$\\{cur\_cmd}=%
\\{toks\_register}$}\6
\&{begin} \37\\{scan\_eight\_bit\_int};\5
$\|m\K\\{toks\_base}+\\{cur\_val}$;\6
\&{end};\2\6
$\\{scanned\_result}(\\{equiv}(\|m))(\\{tok\_val})$;\6
\&{end}\6
\4\&{else} \&{begin} \37\\{back\_input};\5
\\{scan\_font\_ident};\5
$\\{scanned\_result}(\\{font\_id\_base}+\\{cur\_val})(\\{ident\_val})$;\6
\&{end}\2\2\par
\U section~413.\fi

\M416. A user is allowed to refer to `\.{\\the\\spacefactor}' only in
horizontal
mode, and to `\.{\\the\\prevdepth}' only in vertical mode; so we put the
associated mode in the modifier part of the \\{set\_aux} command.
The \\{set\_page\_int} command has modifier 0 or 1, for `\.{\\deadcycles}' and
`\.{\\insertpenalties}', respectively. The \\{set\_box\_dimen} command is
modified by either \\{width\_offset}, \\{height\_offset}, or \\{depth\_offset}.
The \\{last\_item} command is modified by either \\{int\_val}, \\{dimen\_val},
or \\{glue\_val}.

\Y\P$\4\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}\S$\6
$\\{primitive}(\.{"spacefactor"},\39\\{set\_aux},\39\\{hmode})$;\5
$\\{primitive}(\.{"prevdepth"},\39\\{set\_aux},\39\\{vmode})$;\6
$\\{primitive}(\.{"deadcycles"},\39\\{set\_page\_int},\390)$;\5
$\\{primitive}(\.{"insertpenalties"},\39\\{set\_page\_int},\391)$;\5
$\\{primitive}(\.{"wd"},\39\\{set\_box\_dimen},\39\\{width\_offset})$;\5
$\\{primitive}(\.{"ht"},\39\\{set\_box\_dimen},\39\\{height\_offset})$;\5
$\\{primitive}(\.{"dp"},\39\\{set\_box\_dimen},\39\\{depth\_offset})$;\5
$\\{primitive}(\.{"lastpenalty"},\39\\{last\_item},\39\\{int\_val})$;\5
$\\{primitive}(\.{"lastkern"},\39\\{last\_item},\39\\{dimen\_val})$;\5
$\\{primitive}(\.{"lastskip"},\39\\{last\_item},\39\\{glue\_val})$;\par
\fi

\M417. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{set\_aux}: \37\&{if} $\\{chr\_code}=\\{vmode}$ \1\&{then}\5
$\\{print\_esc}(\.{"prevdepth"})$\6
\4\&{else} $\\{print\_esc}(\.{"spacefactor"})$;\2\6
\4\\{set\_page\_int}: \37\&{if} $\\{chr\_code}=0$ \1\&{then}\5
$\\{print\_esc}(\.{"deadcycles"})$\6
\4\&{else} $\\{print\_esc}(\.{"insertpenalties"})$;\2\6
\4\\{set\_box\_dimen}: \37\&{if} $\\{chr\_code}=\\{width\_offset}$ \1\&{then}\5
$\\{print\_esc}(\.{"wd"})$\6
\4\&{else} \&{if} $\\{chr\_code}=\\{height\_offset}$ \1\&{then}\5
$\\{print\_esc}(\.{"ht"})$\6
\4\&{else} $\\{print\_esc}(\.{"dp"})$;\2\2\6
\4\\{last\_item}: \37\&{if} $\\{chr\_code}=\\{int\_val}$ \1\&{then}\5
$\\{print\_esc}(\.{"lastpenalty"})$\6
\4\&{else} \&{if} $\\{chr\_code}=\\{dimen\_val}$ \1\&{then}\5
$\\{print\_esc}(\.{"lastkern"})$\6
\4\&{else} $\\{print\_esc}(\.{"lastskip"})$;\2\2\par
\fi

\M418. \P$\X418:Fetch the \\{space\_factor} or the \\{prev\_depth}\X\S$\6
\&{if} $\\{abs}(\\{mode})\I\|m$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Improper\ "})$;\5
$\\{print\_cmd\_chr}(\\{set\_aux},\39\|m)$;\5
$\\{help4}(\.{"You\ can\ refer\ to\ \\spacefactor\ only\ in\ horizontal\
mode;"})$\6
$(\.{"you\ can\ refer\ to\ \\prevdepth\ only\ in\ vertical\ mode;\ and"})$\6
$(\.{"neither\ of\ these\ is\ meaningful\ inside\ \\write.\ So"})$\6
$(\.{"I\'m\ forgetting\ what\ you\ said\ and\ using\ zero\ instead."})$;\5
\\{error};\6
\&{if} $\\{level}\I\\{tok\_val}$ \1\&{then}\5
$\\{scanned\_result}(0)(\\{dimen\_val})$\6
\4\&{else} $\\{scanned\_result}(0)(\\{int\_val})$;\2\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{cur\_val}\K\\{aux}$;\6
\&{if} $\|m=\\{vmode}$ \1\&{then}\5
$\\{cur\_val\_level}\K\\{dimen\_val}$\ \&{else} $\\{cur\_val\_level}\K\\{int%
\_val}$;\2\6
\&{end}\2\par
\U section~413.\fi

\M419. \P$\X419:Fetch the \\{dead\_cycles} or the \\{insert\_penalties}\X\S$\6
\&{begin} \37\&{if} $\|m=0$ \1\&{then}\5
$\\{cur\_val}\K\\{dead\_cycles}$\ \&{else} $\\{cur\_val}\K\\{insert%
\_penalties}$;\2\6
$\\{cur\_val\_level}\K\\{int\_val}$;\6
\&{end}\par
\U section~413.\fi

\M420. \P$\X420:Fetch a box dimension\X\S$\6
\&{begin} \37\\{scan\_eight\_bit\_int};\6
\&{if} $\\{box}(\\{cur\_val})=\\{null}$ \1\&{then}\5
$\\{cur\_val}\K0$\ \&{else} $\\{cur\_val}\K\\{mem}[\\{box}(\\{cur\_val})+\|m].%
\\{sc}$;\2\6
$\\{cur\_val\_level}\K\\{dimen\_val}$;\6
\&{end}\par
\U section~413.\fi

\M421. \P\D \37$\\{max\_dimen}\S\O{7777777777}$\C{$2↑{30}-1$}\par
\Y\P$\4\X421:Fetch something on the \\{page\_so\_far}\X\S$\6
\&{begin} \37\&{if} $\\{page\_contents}=\\{empty}$ \1\&{then}\6
\&{if} $\|m=0$ \1\&{then}\5
$\\{cur\_val}\K\\{max\_dimen}$\ \&{else} $\\{cur\_val}\K0$\2\6
\4\&{else} $\\{cur\_val}\K\\{page\_so\_far}[\|m]$;\2\6
$\\{cur\_val\_level}\K\\{dimen\_val}$;\6
\&{end}\par
\U section~413.\fi

\M422. \P$\X422:Fetch the \\{prev\_graf}\X\S$\6
\&{begin} \37$\\{nest}[\\{nest\_ptr}]\K\\{cur\_list}$;\5
$\|p\K\\{nest\_ptr}$;\6
\&{while} $\\{abs}(\\{nest}[\|p].\\{mode\_field})\I\\{vmode}$ \1\&{do}\5
$\\{decr}(\|p)$;\2\6
$\\{scanned\_result}(\\{nest}[\|p].\\{pg\_field})(\\{int\_val})$;\6
\&{end}\par
\U section~413.\fi

\M423. \P$\X423:Fetch the \\{par\_shape} size\X\S$\6
\&{begin} \37\&{if} $\\{par\_shape\_ptr}=\\{null}$ \1\&{then}\5
$\\{cur\_val}\K0$\6
\4\&{else} $\\{cur\_val}\K\\{info}(\\{par\_shape\_ptr})$;\2\6
$\\{cur\_val\_level}\K\\{int\_val}$;\6
\&{end}\par
\U section~413.\fi

\M424. Here is where \.{\\lastpenalty}, \.{\\lastkern}, and \.{\\lastskip} are
implemented. The reference count for \.{\\lastskip} will be updated later.

\Y\P$\4\X424:Fetch an item in the current node, if appropriate\X\S$\6
\&{begin} \37\&{if} $\\{cur\_chr}=\\{glue\_val}$ \1\&{then}\5
$\\{cur\_val}\K\\{zero\_glue}$\ \&{else} $\\{cur\_val}\K0$;\2\6
$\\{cur\_val\_level}\K\\{cur\_chr}$;\6
\&{if} $\R\\{is\_char\_node}(\\{tail})\W(\\{mode}\I0)$ \1\&{then}\6
\&{case} $\\{cur\_chr}$ \1\&{of}\6
\4\\{int\_val}: \37\&{if} $\\{type}(\\{tail})=\\{penalty\_node}$ \1\&{then}\5
$\\{cur\_val}\K\\{penalty}(\\{tail})$;\2\6
\4\\{dimen\_val}: \37\&{if} $\\{type}(\\{tail})=\\{kern\_node}$ \1\&{then}\5
$\\{cur\_val}\K\\{width}(\\{tail})$;\2\6
\4\\{glue\_val}: \37\&{if} $\\{type}(\\{tail})=\\{glue\_node}$ \1\&{then}\6
\&{begin} \37$\\{cur\_val}\K\\{glue\_ptr}(\\{tail})$;\6
\&{if} $\\{subtype}(\\{tail})=\\{mu\_glue}$ \1\&{then}\5
$\\{cur\_val\_level}\K\\{mu\_val}$;\2\6
\&{end};\2\2\6
\&{end}\C{there are no other cases}\6
\4\&{else} \&{if} $(\\{mode}=\\{vmode})\W(\\{tail}=\\{head})$ \1\&{then}\6
\&{case} $\\{cur\_chr}$ \1\&{of}\6
\4\\{int\_val}: \37$\\{cur\_val}\K\\{last\_penalty}$;\6
\4\\{dimen\_val}: \37$\\{cur\_val}\K\\{last\_kern}$;\6
\4\\{glue\_val}: \37\&{if} $\\{last\_glue}\I\\{max\_halfword}$ \1\&{then}\5
$\\{cur\_val}\K\\{last\_glue}$;\2\2\6
\&{end};\C{there are no other cases}\2\2\6
\&{end}\par
\U section~413.\fi

\M425. \P$\X425:Fetch a font dimension\X\S$\6
\&{begin} \37$\\{find\_font\_dimen}(\\{false})$;\5
$\\{font\_info}[\\{fmem\_ptr}].\\{sc}\K0$;\5
$\\{scanned\_result}(\\{font\_info}[\\{cur\_val}].\\{sc})(\\{dimen\_val})$;\6
\&{end}\par
\U section~413.\fi

\M426. \P$\X426:Fetch a font integer\X\S$\6
\&{begin} \37\\{scan\_font\_ident};\6
\&{if} $\|m=0$ \1\&{then}\5
$\\{scanned\_result}(\\{hyphen\_char}[\\{cur\_val}])(\\{int\_val})$\6
\4\&{else} $\\{scanned\_result}(\\{skew\_char}[\\{cur\_val}])(\\{int\_val})$;\2%
\6
\&{end}\par
\U section~413.\fi

\M427. \P$\X427:Fetch a register\X\S$\6
\&{begin} \37\\{scan\_eight\_bit\_int};\6
\&{case} $\|m$ \1\&{of}\6
\4\\{int\_val}: \37$\\{cur\_val}\K\\{count}(\\{cur\_val})$;\6
\4\\{dimen\_val}: \37$\\{cur\_val}\K\\{dimen}(\\{cur\_val})$;\6
\4\\{glue\_val}: \37$\\{cur\_val}\K\\{skip}(\\{cur\_val})$;\6
\4\\{mu\_val}: \37$\\{cur\_val}\K\\{mu\_skip}(\\{cur\_val})$;\2\6
\&{end};\C{there are no other cases}\6
$\\{cur\_val\_level}\K\|m$;\6
\&{end}\par
\U section~413.\fi

\M428. \P$\X428:Complain that \.{\\the} can't do this; give zero result\X\S$\6
\&{begin} \37$\\{print\_err}(\.{"You\ can\'t\ use\ \`"})$;\5
$\\{print\_cmd\_chr}(\\{cur\_cmd},\39\\{cur\_chr})$;\5
$\\{print}(\.{"\'\ after\ "})$;\5
$\\{print\_esc}(\.{"the"})$;\5
$\\{help1}(\.{"I\'m\ forgetting\ what\ you\ said\ and\ using\ zero\
instead."})$;\5
\\{error};\6
\&{if} $\\{level}\I\\{tok\_val}$ \1\&{then}\5
$\\{scanned\_result}(0)(\\{dimen\_val})$\6
\4\&{else} $\\{scanned\_result}(0)(\\{int\_val})$;\2\6
\&{end}\par
\U section~413.\fi

\M429. When a \\{glue\_val} changes to a \\{dimen\_val}, we use the width
component
of the glue; there is no need to decrease the reference count, since it
has not yet been increased.  When a \\{dimen\_val} changes to an \\{int\_val},
we use scaled points so that the value doesn't actually change. And when a
\\{mu\_val} changes to a \\{glue\_val}, the value doesn't change either.

\Y\P$\4\X429:Convert \(c)\\{cur\_val} to a lower level\X\S$\6
\&{begin} \37\&{if} $\\{cur\_val\_level}=\\{glue\_val}$ \1\&{then}\5
$\\{cur\_val}\K\\{width}(\\{cur\_val})$\6
\4\&{else} \&{if} $\\{cur\_val\_level}=\\{mu\_val}$ \1\&{then}\5
\\{mu\_error};\2\2\6
$\\{decr}(\\{cur\_val\_level})$;\6
\&{end}\par
\U section~413.\fi

\M430. If \\{cur\_val} points to a glue specification at this point, the
reference
count for the glue does not yet include the reference by \\{cur\_val}.
If \\{negative} is \\{true}, \\{cur\_val\_level} is known to be $\L\\{mu%
\_val}$.

\Y\P$\4\X430:Fix the reference count, if any, and negate \\{cur\_val} if %
\\{negative}\X\S$\6
\&{if} $\\{negative}$ \1\&{then}\6
\&{if} $\\{cur\_val\_level}\G\\{glue\_val}$ \1\&{then}\6
\&{begin} \37$\\{cur\_val}\K\\{new\_spec}(\\{cur\_val})$;\5
\X431:Negate all three glue components of \\{cur\_val}\X;\6
\&{end}\6
\4\&{else} $\\{negate}(\\{cur\_val})$\2\6
\4\&{else} \&{if} $(\\{cur\_val\_level}\G\\{glue\_val})\W(\\{cur\_val\_level}\L%
\\{mu\_val})$ \1\&{then}\5
$\\{add\_glue\_ref}(\\{cur\_val})$\2\2\par
\U section~413.\fi

\M431. \P$\X431:Negate all three glue components of \\{cur\_val}\X\S$\6
\&{begin} \37$\\{negate}(\\{width}(\\{cur\_val}))$;\5
$\\{negate}(\\{stretch}(\\{cur\_val}))$;\5
$\\{negate}(\\{shrink}(\\{cur\_val}))$;\6
\&{end}\par
\U section~430.\fi

\M432. Our next goal is to write the \\{scan\_int} procedure, which scans
anything that
\TeX\ treats as an integer. But first we might as well look at some simple
applications of \\{scan\_int} that have already been made inside of
\\{scan\_something\_internal}:

\Y\P$\4\X432:Declare procedures that scan restricted classes of integers\X\S$\6
\4\&{procedure}\1\  \37\\{scan\_seven\_bit\_int};\2\6
\&{begin} \37\\{scan\_int};\6
\&{if} $(\\{cur\_val}<0)\V(\\{cur\_val}>127)$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Bad\ character\ code"})$;\5
$\\{help2}(\.{"The\ numeric\ code\ for\ a\ character\ must\ be\ between\ 0\ and%
\ 127."})$\6
$(\.{"I\ changed\ this\ one\ to\ zero."})$;\5
$\\{int\_error}(\\{cur\_val})$;\5
$\\{cur\_val}\K0$;\6
\&{end};\2\6
\&{end};\par
\A sections~433, 434, 435\*, 436, and~437.
\U section~409.\fi

\M433. \P$\X432:Declare procedures that scan restricted classes of integers\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{scan\_eight\_bit\_int};\2\6
\&{begin} \37\\{scan\_int};\6
\&{if} $(\\{cur\_val}<0)\V(\\{cur\_val}>255)$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Bad\ register\ code"})$;\5
$\\{help2}(\.{"A\ register\ number\ must\ be\ between\ 0\ and\ 255."})$\6
$(\.{"I\ changed\ this\ one\ to\ zero."})$;\5
$\\{int\_error}(\\{cur\_val})$;\5
$\\{cur\_val}\K0$;\6
\&{end};\2\6
\&{end};\par
\fi

\M434. \P$\X432:Declare procedures that scan restricted classes of integers\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{scan\_four\_bit\_int};\2\6
\&{begin} \37\\{scan\_int};\6
\&{if} $(\\{cur\_val}<0)\V(\\{cur\_val}>15)$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Bad\ number"})$;\5
$\\{help2}(\.{"Since\ I\ expected\ to\ read\ a\ number\ between\ 0\ and\
15,"})$\6
$(\.{"I\ changed\ this\ one\ to\ zero."})$;\5
$\\{int\_error}(\\{cur\_val})$;\5
$\\{cur\_val}\K0$;\6
\&{end};\2\6
\&{end};\par
\fi

\M435\*. While we're at it, we might as well deal with similar routines that
will be needed later.

\Y\P$\4\X432:Declare procedures that scan restricted classes of integers\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{scan\_xchar\_num};\2\6
\&{begin} \37\\{scan\_int};\6
\&{if} $(\\{cur\_val}<0)\V(\\{cur\_val}>65535)$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Bad\ character\ code"})$;\5
$\\{help2}(\.{"An\ \\xchar\ number\ must\ be\ between\ 0\ and\ 255."})$\6
$(\.{"I\ changed\ this\ one\ to\ zero."})$;\5
$\\{int\_error}(\\{cur\_val})$;\5
$\\{cur\_val}\K0$;\6
\&{end};\2\6
\&{end};\7
\4\&{procedure}\1\  \37\\{scan\_char\_num};\2\6
\&{begin} \37\\{scan\_int};\6
\&{if} $(\\{cur\_val}<0)\V(\\{cur\_val}>255)$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Bad\ character\ code"})$;\5
$\\{help2}(\.{"A\ character\ number\ must\ be\ between\ 0\ and\ 255."})$\6
$(\.{"I\ changed\ this\ one\ to\ zero."})$;\5
$\\{int\_error}(\\{cur\_val})$;\5
$\\{cur\_val}\K0$;\6
\&{end};\2\6
\&{end};\par
\fi

\M436. \P$\X432:Declare procedures that scan restricted classes of integers\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{scan\_fifteen\_bit\_int};\2\6
\&{begin} \37\\{scan\_int};\6
\&{if} $(\\{cur\_val}<0)\V(\\{cur\_val}>\O{77777})$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Bad\ math\ code"})$;\5
$\\{help2}(\.{"A\ numeric\ math\ code\ must\ be\ between\ 0\ and\ 32767."})$\6
$(\.{"I\ changed\ this\ one\ to\ zero."})$;\5
$\\{int\_error}(\\{cur\_val})$;\5
$\\{cur\_val}\K0$;\6
\&{end};\2\6
\&{end};\par
\fi

\M437. \P$\X432:Declare procedures that scan restricted classes of integers\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{scan\_twenty\_seven\_bit\_int};\2\6
\&{begin} \37\\{scan\_int};\6
\&{if} $(\\{cur\_val}<0)\V(\\{cur\_val}>\O{777777777})$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Bad\ delimiter\ code"})$;\5
$\\{help2}(\.{"A\ numeric\ delimiter\ code\ must\ be\ between\ 0\ and\ 2\↑\{27%
\}-1."})$\6
$(\.{"I\ changed\ this\ one\ to\ zero."})$;\5
$\\{int\_error}(\\{cur\_val})$;\5
$\\{cur\_val}\K0$;\6
\&{end};\2\6
\&{end};\par
\fi

\M438. An integer number can be preceded by any number of spaces and `\.+' or
`\.-' signs. Then comes either a decimal constant (i.e., radix 10), an
octal constant (i.e., radix 8, preceded by~\.\'), a hexadecimal constant
(radix 16, preceded by~\."), an alphabetic constant (preceded by~\.\`), or
an internal variable. After scanning is complete,
\\{cur\_val} will contain the answer, which must be at most
$2↑{31}-1=2147483647$ in absolute value. The value of \\{radix} is set to
10, 8, or 16 in the cases of decimal, octal, or hexadecimal constants,
otherwise \\{radix} is set to zero. An optional space follows a constant.

\Y\P\D \37$\\{octal\_token}=\\{other\_token}+\.{"\'"}$\C{apostrophe, indicates
an octal constant}\par
\P\D \37$\\{hex\_token}=\\{other\_token}+\.{""}\.{""}$\C{double quote,
indicates a hex constant}\par
\P\D \37$\\{alpha\_token}=\\{other\_token}+\.{"\`"}$\C{reverse apostrophe,
precedes alpha constants}\par
\P\D \37$\\{point\_token}=\\{other\_token}+\.{"."}$\C{decimal point}\par
\P\D \37$\\{continental\_point\_token}=\\{other\_token}+\.{","}$\C{decimal
point, Eurostyle}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{radix}: \37\\{small\_number};\C{\\{scan\_int} sets this to 8, 10, 16, or
zero}\par
\fi

\M439. We initialize the following global variables just in case \\{expand}
comes into action before any of the basic scanning routines has assigned
them a value.

\Y\P$\4\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{cur\_val}\K0$;\5
$\\{cur\_val\_level}\K\\{int\_val}$;\5
$\\{radix}\K0$;\par
\fi

\M440\*. The \\{scan\_int} routine is used also to scan the integer part of a
fraction; for example, the `\.3' in `\.{3.14159}' will be found by
\\{scan\_int}. The \\{scan\_dimen} routine assumes that $\\{cur\_tok}=\\{point%
\_token}$
after the integer part of such a fraction has been scanned by \\{scan\_int},
and that the decimal point has been backed up to be scanned again.

\Y\P\4\&{procedure}\1\  \37\\{scan\_int};\C{sets \\{cur\_val} to an integer}\6
\4\&{label} \37\\{done};\6
\4\&{var} \37\\{negative}: \37\\{boolean};\C{should the answer be negated?}\6
\|m: \37\\{integer};\C{$\hbox{$2↑{31}$}\mathbin{\&{div}}\\{radix}$, the
threshold of danger}\6
\|d: \37\\{small\_number};\C{the digit just scanned}\6
\\{vacuous}: \37\\{boolean};\C{have no digits appeared?}\6
\\{OK\_so\_far}: \37\\{boolean};\C{has an error message been issued?}\2\6
\&{begin} \37$\\{radix}\K0$;\5
$\\{OK\_so\_far}\K\\{true}$;\6
$\\{incr}(\\{trace\_depth})$;\6
\&{if} $\\{tracing\_stats}>2$ \1\&{then}\5
$\\{print}(\.{"\ <i"})$;\2\6
\X441:Get the next non-blank non-sign token; set \\{negative} appropriately\X;\6
\&{if} $\\{cur\_tok}=\\{alpha\_token}$ \1\&{then}\5
\X442:Scan an alphabetic character code into \\{cur\_val}\X\6
\4\&{else} \&{if} $(\\{cur\_cmd}\G\\{min\_internal})\W(\\{cur\_cmd}\L\\{max%
\_internal})$ \1\&{then}\5
$\\{scan\_something\_internal}(\\{int\_val},\39\\{false})$\6
\4\&{else} \X444:Scan a numeric constant\X;\2\2\6
\&{if} $\\{negative}$ \1\&{then}\5
$\\{negate}(\\{cur\_val})$;\2\6
$\\{decr}(\\{trace\_depth})$;\6
\&{if} $\\{tracing\_stats}>2$ \1\&{then}\5
$\\{print\_char}(\.{">"})$;\2\6
\&{end};\par
\fi

\M441. \P$\X441:Get the next non-blank non-sign token; set \\{negative}
appropriately\X\S$\6
$\\{negative}\K\\{false}$;\6
\1\&{repeat} \37\X406:Get the next non-blank non-call token\X;\6
\&{if} $\\{cur\_tok}=\\{other\_token}+\.{"-"}$ \1\&{then}\6
\&{begin} \37$\\{negative}\K\R\\{negative}$;\5
$\\{cur\_tok}\K\\{other\_token}+\.{"+"}$;\6
\&{end};\2\6
\4\&{until}\5
$\\{cur\_tok}\I\\{other\_token}+\.{"+"}$\2\par
\U sections~440\*, 448\*, and~461.\fi

\M442. A space is ignored after an alphabetic character constant, so that
such constants behave like numeric ones.

\Y\P$\4\X442:Scan an alphabetic character code into \\{cur\_val}\X\S$\6
\&{begin} \37\\{get\_token};\C{suppress macro expansion}\6
\&{if} $\\{cur\_tok}<\\{cs\_token\_flag}$ \1\&{then}\6
\&{begin} \37$\\{cur\_val}\K\\{cur\_chr}$;\6
\&{if} $\\{cur\_cmd}\L\\{right\_brace}$ \1\&{then}\6
\&{if} $\\{cur\_cmd}=\\{right\_brace}$ \1\&{then}\5
$\\{incr}(\\{align\_state})$\6
\4\&{else} $\\{decr}(\\{align\_state})$;\2\2\6
\&{end}\6
\4\&{else} \&{if} $\\{cur\_tok}<\\{cs\_token\_flag}+\\{single\_base}$ \1%
\&{then}\5
$\\{cur\_val}\K\\{cur\_tok}-\\{cs\_token\_flag}-\\{active\_base}$\6
\4\&{else} $\\{cur\_val}\K\\{cur\_tok}-\\{cs\_token\_flag}-\\{single\_base}$;\2%
\2\6
\&{if} $\\{cur\_val}>127$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Improper\ alphabetic\ constant"})$;\5
$\\{help2}(\.{"A\ one-character\ control\ sequence\ belongs\ after\ a\ \`\
mark."})$\6
$(\.{"So\ I\'m\ essentially\ inserting\ \\0\ here."})$;\5
$\\{cur\_val}\K\.{"0"}$;\5
\\{back\_error};\6
\&{end}\6
\4\&{else} \X443:Scan an optional space\X;\2\6
\&{end}\par
\U section~440\*.\fi

\M443. \P$\X443:Scan an optional space\X\S$\6
\&{begin} \37\\{get\_x\_token};\6
\&{if} $\\{cur\_cmd}\I\\{spacer}$ \1\&{then}\5
\\{back\_input};\2\6
\&{end}\par
\U sections~442, 448\*, 455, and~1200.\fi

\M444. \P$\X444:Scan a numeric constant\X\S$\6
\&{begin} \37$\\{radix}\K10$;\5
$\|m\K214748364$;\6
\&{if} $\\{cur\_tok}=\\{octal\_token}$ \1\&{then}\6
\&{begin} \37$\\{radix}\K8$;\5
$\|m\K\O{2000000000}$;\5
\\{get\_x\_token};\6
\&{end}\6
\4\&{else} \&{if} $\\{cur\_tok}=\\{hex\_token}$ \1\&{then}\6
\&{begin} \37$\\{radix}\K16$;\5
$\|m\K\O{1000000000}$;\5
\\{get\_x\_token};\6
\&{end};\2\2\6
$\\{vacuous}\K\\{true}$;\5
$\\{cur\_val}\K0$;\6
\X445:Accumulate the constant until \\{cur\_tok} is not a suitable digit\X;\6
\&{if} $\\{vacuous}$ \1\&{then}\5
\X446:Express astonishment that no number was here\X\6
\4\&{else} \&{if} $\\{cur\_cmd}\I\\{spacer}$ \1\&{then}\5
\\{back\_input};\2\2\6
\&{end}\par
\U section~440\*.\fi

\M445. \P\D \37$\\{infinity}\S\O{17777777777}$\C{the largest positive value
that \TeX\ knows}\par
\P\D \37$\\{zero\_token}=\\{other\_token}+\.{"0"}$\C{zero, the smallest digit}%
\par
\P\D \37$\\{A\_token}=\\{letter\_token}+\.{"A"}$\C{the smallest special hex
digit}\par
\P\D \37$\\{other\_A\_token}=\\{other\_token}+\.{"A"}$\C{special hex digit of
type \\{other\_char}}\par
\Y\P$\4\X445:Accumulate the constant until \\{cur\_tok} is not a suitable digit%
\X\S$\6
\~ \1\&{loop}\ \&{begin} \37\&{if} $(\\{cur\_tok}<\\{zero\_token}+\\{radix})\W(%
\\{cur\_tok}\G\\{zero\_token})\W(\\{cur\_tok}\L\\{zero\_token}+9)$ \1\&{then}\5
$\|d\K\\{cur\_tok}-\\{zero\_token}$\6
\4\&{else} \&{if} $\\{radix}=16$ \1\&{then}\6
\&{if} $(\\{cur\_tok}\L\\{A\_token}+5)\W(\\{cur\_tok}\G\\{A\_token})$ \1%
\&{then}\5
$\|d\K\\{cur\_tok}-\\{A\_token}+10$\6
\4\&{else} \&{if} $(\\{cur\_tok}\L\\{other\_A\_token}+5)\W(\\{cur\_tok}\G%
\\{other\_A\_token})$ \1\&{then}\5
$\|d\K\\{cur\_tok}-\\{other\_A\_token}+10$\6
\4\&{else} \&{goto} \37\\{done}\2\2\6
\4\&{else} \&{goto} \37\\{done};\2\2\6
$\\{vacuous}\K\\{false}$;\6
\&{if} $(\\{cur\_val}\G\|m)\W((\\{cur\_val}>\|m)\V(\|d>7)\V(\\{radix}\I10))$ \1%
\&{then}\6
\&{begin} \37\&{if} $\\{OK\_so\_far}$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Number\ too\ big"})$;\5
$\\{help2}(\.{"I\ can\ only\ go\ up\ to\ 2147483647=\'17777777777="}%
\.{"7FFFFFFF,"})$\6
$(\.{"so\ I\'m\ using\ that\ number\ instead\ of\ yours."})$;\5
\\{error};\5
$\\{cur\_val}\K\\{infinity}$;\5
$\\{OK\_so\_far}\K\\{false}$;\6
\&{end};\2\6
\&{end}\6
\4\&{else} $\\{cur\_val}\K\\{cur\_val}\ast\\{radix}+\|d$;\2\6
\\{get\_x\_token};\6
\&{end};\2\6
\4\\{done}: \37\par
\U section~444.\fi

\M446. \P$\X446:Express astonishment that no number was here\X\S$\6
\&{begin} \37$\\{print\_err}(\.{"Missing\ number,\ treated\ as\ zero"})$;\5
$\\{help3}(\.{"A\ number\ should\ have\ been\ here;\ I\ inserted\ \`0\'."})$\6
$(\.{"(If\ you\ can\'t\ figure\ out\ why\ I\ needed\ to\ see\ a\ number,"})$\6
$(\.{"look\ up\ \`weird\ error\'\ in\ the\ index\ to\ The\ TeXbook.)"})$;\5
\\{back\_error};\6
\&{end}\par
\U section~444.\fi

\M447. The \\{scan\_dimen} routine is similar to \\{scan\_int}, but it sets %
\\{cur\_val} to
a \\{scaled} value, i.e., an integral number of sp. One of its main tasks
is therefore to interpret the abbreviations for various kinds of units and
to convert measurements to scaled points.

There are three parameters: \\{mu} is \\{true} if the finite units must be
`\.{mu}', while \\{mu} is \\{false} if `\.{mu}' units are disallowed;
\\{inf} is \\{true} if the infinite units `\.{fil}', `\.{fill}', `\.{filll}'
are permitted; and \\{shortcut} is \\{true} if \\{cur\_val} already contains
an integer and only the units need to be considered.

The order of infinity that was found in the case of infinite glue is returned
in the global variable \\{cur\_order}.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{cur\_order}: \37\\{glue\_ord};\C{order of infinity found by \\{scan%
\_dimen}}\par
\fi

\M448\*. Constructions like `\.{-\'77 pt}' are legal dimensions, so \\{scan%
\_dimen}
may begin with \\{scan\_int}. This explains why it is convenient to use
\\{scan\_int} also for the integer part of a decimal fraction.

Several branches of \\{scan\_dimen} work with \\{cur\_val} as an integer and
with an auxiliary fraction \|f, so that the actual quantity of interest is
$\\{cur\_val}+\|f/2↑{16}$. At the end of the routine, this ``unpacked''
representation is put into the single word \\{cur\_val}, which suddenly
switches significance from \\{integer} to \\{scaled}.

\Y\P\D \37$\\{attach\_fraction}=88$\C{go here to pack \\{cur\_val} and \|f into
\\{cur\_val}}\par
\P\D \37$\\{attach\_sign}=89$\C{go here when \\{cur\_val} is correct except
perhaps for sign}\par
\P\D \37$\\{scan\_normal\_dimen}\S\\{scan\_dimen}(\\{false},\39\\{false},\39%
\\{false})$\par
\Y\P\4\&{procedure}\1\  \37$\\{scan\_dimen}(\\{mu},\39\\{inf},\39\\{shortcut}:%
\\{boolean})$;\C{sets \\{cur\_val} to a dimension}\6
\4\&{label} \37$\\{done},\39\\{done1},\39\\{done2},\39\\{found},\39\\{not%
\_found},\39\\{attach\_fraction},\39\\{attach\_sign}$;\6
\4\&{var} \37\\{negative}: \37\\{boolean};\C{should the answer be negated?}\6
\|f: \37\\{integer};\C{numerator of a fraction whose denominator is $2↑{16}$}\6
\X450:Local variables for dimension calculations\X\2\6
\&{begin} \37$\|f\K0$;\5
$\\{arith\_error}\K\\{false}$;\5
$\\{cur\_order}\K\\{normal}$;\5
$\\{negative}\K\\{false}$;\5
$\\{incr}(\\{trace\_depth})$;\6
\&{if} $\\{tracing\_stats}>2$ \1\&{then}\5
$\\{print}(\.{"\ <d"})$;\2\6
\&{if} $\R\\{shortcut}$ \1\&{then}\6
\&{begin} \37\X441:Get the next non-blank non-sign token; set \\{negative}
appropriately\X;\6
\&{if} $(\\{cur\_cmd}\G\\{min\_internal})\W(\\{cur\_cmd}\L\\{max\_internal})$ %
\1\&{then}\5
\X449:Fetch an internal dimension and \&{goto} \\{attach\_sign}, or fetch an
internal integer\X\6
\4\&{else} \&{begin} \37\\{back\_input};\6
\&{if} $\\{cur\_tok}=\\{continental\_point\_token}$ \1\&{then}\5
$\\{cur\_tok}\K\\{point\_token}$;\2\6
\&{if} $\\{cur\_tok}\I\\{point\_token}$ \1\&{then}\5
\\{scan\_int}\6
\4\&{else} \&{begin} \37$\\{radix}\K10$;\5
$\\{cur\_val}\K0$;\6
\&{end};\2\6
\&{if} $\\{cur\_tok}=\\{continental\_point\_token}$ \1\&{then}\5
$\\{cur\_tok}\K\\{point\_token}$;\2\6
\&{if} $(\\{radix}=10)\W(\\{cur\_tok}=\\{point\_token})$ \1\&{then}\5
\X452:Scan decimal fraction\X;\2\6
\&{end};\2\6
\&{end};\2\6
\&{if} $\\{cur\_val}<0$ \1\&{then}\C{in this case $\|f=0$}\6
\&{begin} \37$\\{negative}\K\R\\{negative}$;\5
$\\{negate}(\\{cur\_val})$;\6
\&{end};\2\6
\X453:Scan units and set \\{cur\_val} to $x\cdot(\\{cur\_val}+f/2↑{16})$, where
there are \|x units per sp; \&{goto} \\{attach\_sign} if the units are internal%
\X;\6
\X443:Scan an optional space\X;\6
\4\\{attach\_sign}: \37\&{if} $\\{arith\_error}\V(\\{abs}(\\{cur\_val})\G%
\O{10000000000})$ \1\&{then}\5
\X460:Report that this dimension is out of range\X;\2\6
\&{if} $\\{negative}$ \1\&{then}\5
$\\{negate}(\\{cur\_val})$;\2\6
$\\{decr}(\\{trace\_depth})$;\6
\&{if} $\\{tracing\_stats}>2$ \1\&{then}\5
$\\{print\_char}(\.{">"})$;\2\6
\&{end};\par
\fi

\M449. \P$\X449:Fetch an internal dimension and \&{goto} \\{attach\_sign}, or
fetch an internal integer\X\S$\6
\&{if} $\\{mu}$ \1\&{then}\6
\&{begin} \37$\\{scan\_something\_internal}(\\{mu\_val},\39\\{false})$;\5
\X451:Coerce glue to a dimension\X;\6
\&{if} $\\{cur\_val\_level}=\\{mu\_val}$ \1\&{then}\5
\&{goto} \37\\{attach\_sign};\2\6
\&{if} $\\{cur\_val\_level}\I\\{int\_val}$ \1\&{then}\5
\\{mu\_error};\2\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{scan\_something\_internal}(\\{dimen\_val},\39%
\\{false})$;\6
\&{if} $\\{cur\_val\_level}=\\{dimen\_val}$ \1\&{then}\5
\&{goto} \37\\{attach\_sign};\2\6
\&{end}\2\par
\U section~448\*.\fi

\M450. \P$\X450:Local variables for dimension calculations\X\S$\6
\4$\\{num},\39\\{denom}$: \37$1\to65536$;\C{conversion ratio for the scanned
units}\6
\4\|k: \37\\{small\_number};\C{number of digits in a decimal fraction}\6
\4\|v: \37\\{scaled};\C{an internal dimension}\6
\4\\{save\_cur\_val}: \37\\{integer};\C{temporary storage of \\{cur\_val}}\par
\U section~448\*.\fi

\M451. The following code is executed when \\{scan\_something\_internal} was
called asking for \\{mu\_val}, when we really wanted a ``mudimen'' instead
of ``muglue.''

\Y\P$\4\X451:Coerce glue to a dimension\X\S$\6
\&{if} $\\{cur\_val\_level}\G\\{glue\_val}$ \1\&{then}\6
\&{begin} \37$\|v\K\\{width}(\\{cur\_val})$;\5
$\\{delete\_glue\_ref}(\\{cur\_val})$;\5
$\\{cur\_val}\K\|v$;\6
\&{end}\2\par
\U sections~449 and~455.\fi

\M452. When the following code is executed, we have $\\{cur\_tok}=\\{point%
\_token}$, but this
token has been backed up using \\{back\_input}; we must first discard it.

It turns out that a decimal point all by itself is equivalent to `\.{0.0}'.
Let's hope people don't use that fact.

\Y\P$\4\X452:Scan decimal fraction\X\S$\6
\&{begin} \37$\|k\K0$;\5
\\{get\_token};\C{\\{point\_token} is being re-scanned}\6
\~ \1\&{loop}\ \&{begin} \37\\{get\_x\_token};\6
\&{if} $(\\{cur\_tok}>\\{zero\_token}+9)\V(\\{cur\_tok}<\\{zero\_token})$ \1%
\&{then}\5
\&{goto} \37\\{done1};\2\6
\&{if} $\|k<17$ \1\&{then}\C{digits for $\|k\G17$ cannot affect the result}\6
\&{begin} \37$\\{dig}[\|k]\K\\{cur\_tok}-\\{zero\_token}$;\5
$\\{incr}(\|k)$;\6
\&{end};\2\6
\&{end};\2\6
\4\\{done1}: \37$\|f\K\\{round\_decimals}(\|k)$;\6
\&{if} $\\{cur\_cmd}\I\\{spacer}$ \1\&{then}\5
\\{back\_input};\2\6
\&{end}\par
\U section~448\*.\fi

\M453. Now comes the harder part: At this point in the program, \\{cur\_val} is
a
nonnegative integer and $f/2↑{16}$ is a nonnegative fraction less than 1;
we want to multiply the sum of these two quantities by the appropriate
factor, based on the specified units, in order to produce a \\{scaled}
result, and we want to do the calculation with fixed point arithmetic that
does not overflow.

\Y\P$\4\X453:Scan units and set \\{cur\_val} to $x\cdot(\\{cur%
\_val}+f/2↑{16})$, where there are \|x units per sp; \&{goto} \\{attach\_sign}
if the units are internal\X\S$\6
\&{if} $\\{inf}$ \1\&{then}\5
\X454:Scan for \(f)\.{fil} units; \&{goto} \\{attach\_fraction} if found\X;\2\6
\X455:Scan for \(u)units that are internal dimensions; \&{goto} \\{attach%
\_sign} with \\{cur\_val} set if found\X;\6
\&{if} $\\{mu}$ \1\&{then}\5
\X456:Scan for \(m)\.{mu} units and \&{goto} \\{attach\_fraction}\X;\2\6
\&{if} $\\{scan\_keyword}(\.{"true"})$ \1\&{then}\5
\X457:Adjust \(f)for the magnification ratio\X;\2\6
\&{if} $\\{scan\_keyword}(\.{"pt"})$ \1\&{then}\5
\&{goto} \37\\{attach\_fraction};\C{the easy case}\2\6
\X458:Scan for \(a)all other units and adjust \\{cur\_val} and \|f accordingly;
\&{goto} \\{done} in the case of scaled points\X;\6
\4\\{attach\_fraction}: \37\&{if} $\\{cur\_val}\G\O{40000}$ \1\&{then}\5
$\\{arith\_error}\K\\{true}$\6
\4\&{else} $\\{cur\_val}\K\\{cur\_val}\ast\\{unity}+\|f$;\2\6
\4\\{done}: \37\par
\U section~448\*.\fi

\M454. \P$\X454:Scan for \(f)\.{fil} units; \&{goto} \\{attach\_fraction} if
found\X\S$\6
\&{if} $\\{scan\_keyword}(\.{"fil"})$ \1\&{then}\6
\&{begin} \37$\\{cur\_order}\K\\{fil}$;\6
\&{while} $\\{scan\_keyword}(\.{"l"})$ \1\&{do}\6
\&{begin} \37\&{if} $\\{cur\_order}=\\{filll}$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Illegal\ unit\ of\ measure\ ("})$;\5
$\\{print}(\.{"replaced\ by\ filll)"})$;\5
$\\{help1}(\.{"I\ dddon\'t\ go\ any\ higher\ than\ filll."})$;\5
\\{error};\6
\&{end}\6
\4\&{else} $\\{incr}(\\{cur\_order})$;\2\6
\&{end};\2\6
\&{goto} \37\\{attach\_fraction};\6
\&{end}\2\par
\U section~453.\fi

\M455. \P$\X455:Scan for \(u)units that are internal dimensions; \&{goto} %
\\{attach\_sign} with \\{cur\_val} set if found\X\S$\6
$\\{save\_cur\_val}\K\\{cur\_val}$;\5
\X406:Get the next non-blank non-call token\X;\6
\&{if} $(\\{cur\_cmd}<\\{min\_internal})\V(\\{cur\_cmd}>\\{max\_internal})$ \1%
\&{then}\5
\\{back\_input}\6
\4\&{else} \&{begin} \37\&{if} $\\{mu}$ \1\&{then}\6
\&{begin} \37$\\{scan\_something\_internal}(\\{mu\_val},\39\\{false})$;\5
\X451:Coerce glue to a dimension\X;\6
\&{if} $\\{cur\_val\_level}\I\\{mu\_val}$ \1\&{then}\5
\\{mu\_error};\2\6
\&{end}\6
\4\&{else} $\\{scan\_something\_internal}(\\{dimen\_val},\39\\{false})$;\2\6
$\|v\K\\{cur\_val}$;\5
\&{goto} \37\\{found};\6
\&{end};\2\6
\&{if} $\\{mu}$ \1\&{then}\5
\&{goto} \37\\{not\_found};\2\6
\&{if} $\\{scan\_keyword}(\.{"em"})$ \1\&{then}\5
$\|v\K(\X558:The em width for \\{cur\_font}\X)$\6
\4\&{else} \&{if} $\\{scan\_keyword}(\.{"ex"})$ \1\&{then}\5
$\|v\K(\X559:The x-height for \\{cur\_font}\X)$\6
\4\&{else} \&{goto} \37\\{not\_found};\2\2\6
\X443:Scan an optional space\X;\6
\4\\{found}: \37$\\{cur\_val}\K\\{nx\_plus\_y}(\\{save\_cur\_val},\39\|v,\39%
\\{xn\_over\_d}(\|v,\39\|f,\39\O{200000}))$;\5
\&{goto} \37\\{attach\_sign};\6
\4\\{not\_found}: \37\par
\U section~453.\fi

\M456. \P$\X456:Scan for \(m)\.{mu} units and \&{goto} \\{attach\_fraction}\X%
\S$\6
\&{if} $\\{scan\_keyword}(\.{"mu"})$ \1\&{then}\5
\&{goto} \37\\{attach\_fraction}\6
\4\&{else} \&{begin} \37$\\{print\_err}(\.{"Illegal\ unit\ of\ measure\ ("})$;\5
$\\{print}(\.{"mu\ inserted)"})$;\5
$\\{help4}(\.{"The\ unit\ of\ measurement\ in\ math\ glue\ must\ be\ mu."})$\6
$(\.{"To\ recover\ gracefully\ from\ this\ error,\ it\'s\ best\ to"})$\6
$(\.{"delete\ the\ erroneous\ units;\ e.g.,\ type\ \`2\'\ to\ delete"})$\6
$(\.{"two\ letters.\ (See\ Chapter\ 27\ of\ The\ TeXbook.)"})$;\5
\\{error};\5
\&{goto} \37\\{attach\_fraction};\6
\&{end}\2\par
\U section~453.\fi

\M457. \P$\X457:Adjust \(f)for the magnification ratio\X\S$\6
\&{begin} \37\\{prepare\_mag};\6
\&{if} $\\{mag}\I1000$ \1\&{then}\6
\&{begin} \37$\\{cur\_val}\K\\{xn\_over\_d}(\\{cur\_val},\391000,\39\\{mag})$;\5
$\|f\K(1000\ast\|f+\O{200000}\ast\\{remainder})\mathbin{\&{div}}\\{mag}$;\5
$\\{cur\_val}\K\\{cur\_val}+(\|f\mathbin{\&{div}}\O{200000})$;\5
$\|f\K\|f\mathbin{\&{mod}}\O{200000}$;\6
\&{end};\2\6
\&{end}\par
\U section~453.\fi

\M458. All of the necessary conversion factors can be specified exactly as
fractions whose numerator and denominator are 32768 or less.
According to the definitions here, $\rm2660\,dd\approx1000.33297\,mm$;
this agrees well with the value $\rm1000.333\,mm$ cited by Bosshard
in {\sl Technische Grundlagen zur Satzherstellung\/} (Bern, 1980).

\Y\P\D \37$\\{set\_conversion\_end}(\#)\S\\{denom}\K\#$; \6
\&{end} \par
\P\D \37$\\{set\_conversion}(\#)\S$\ \&{begin} \37$\\{num}\K\#$;\5
\\{set\_conversion\_end}\par
\Y\P$\4\X458:Scan for \(a)all other units and adjust \\{cur\_val} and \|f
accordingly; \&{goto} \\{done} in the case of scaled points\X\S$\6
\&{if} $\\{scan\_keyword}(\.{"in"})$ \1\&{then}\5
$\\{set\_conversion}(7227)(100)$\6
\4\&{else} \&{if} $\\{scan\_keyword}(\.{"pc"})$ \1\&{then}\5
$\\{set\_conversion}(12)(1)$\6
\4\&{else} \&{if} $\\{scan\_keyword}(\.{"cm"})$ \1\&{then}\5
$\\{set\_conversion}(7227)(254)$\6
\4\&{else} \&{if} $\\{scan\_keyword}(\.{"mm"})$ \1\&{then}\5
$\\{set\_conversion}(7227)(2540)$\6
\4\&{else} \&{if} $\\{scan\_keyword}(\.{"bp"})$ \1\&{then}\5
$\\{set\_conversion}(7227)(7200)$\6
\4\&{else} \&{if} $\\{scan\_keyword}(\.{"dd"})$ \1\&{then}\5
$\\{set\_conversion}(1238)(1157)$\6
\4\&{else} \&{if} $\\{scan\_keyword}(\.{"cc"})$ \1\&{then}\5
$\\{set\_conversion}(14856)(1157)$\6
\4\&{else} \&{if} $\\{scan\_keyword}(\.{"sp"})$ \1\&{then}\5
\&{goto} \37\\{done}\6
\4\&{else} \X459:Complain about unknown unit and \&{goto} \\{done2}\X;\2\2\2\2%
\2\2\2\2\6
$\\{cur\_val}\K\\{xn\_over\_d}(\\{cur\_val},\39\\{num},\39\\{denom})$;\5
$\|f\K(\\{num}\ast\|f+\O{200000}\ast\\{remainder})\mathbin{\&{div}}\\{denom}$;\6
$\\{cur\_val}\K\\{cur\_val}+(\|f\mathbin{\&{div}}\O{200000})$;\5
$\|f\K\|f\mathbin{\&{mod}}\O{200000}$;\6
\4\\{done2}: \37\par
\U section~453.\fi

\M459. \P$\X459:Complain about unknown unit and \&{goto} \\{done2}\X\S$\6
\&{begin} \37$\\{print\_err}(\.{"Illegal\ unit\ of\ measure\ ("})$;\5
$\\{print}(\.{"pt\ inserted)"})$;\5
$\\{help6}(\.{"Dimensions\ can\ be\ in\ units\ of\ em,\ ex,\ in,\ pt,\ pc,"})$\6
$(\.{"cm,\ mm,\ dd,\ cc,\ bp,\ or\ sp;\ but\ yours\ is\ a\ new\ one!"})$\6
$(\.{"I\'ll\ assume\ that\ you\ meant\ to\ say\ pt,\ for\ printers\'\
points."})$\6
$(\.{"To\ recover\ gracefully\ from\ this\ error,\ it\'s\ best\ to"})$\6
$(\.{"delete\ the\ erroneous\ units;\ e.g.,\ type\ \`2\'\ to\ delete"})$\6
$(\.{"two\ letters.\ (See\ Chapter\ 27\ of\ The\ TeXbook.)"})$;\5
\\{error};\5
\&{goto} \37\\{done2};\6
\&{end}\par
\U section~458.\fi

\M460. \P$\X460:Report that this dimension is out of range\X\S$\6
\&{begin} \37$\\{print\_err}(\.{"Dimension\ too\ large"})$;\5
$\\{help2}(\.{"I\ can\'t\ work\ with\ sizes\ bigger\ than\ about\ 19\ feet."})$%
\6
$(\.{"Continue\ and\ I\'ll\ use\ the\ largest\ value\ I\ can."})$;\6
\\{error};\5
$\\{cur\_val}\K\\{max\_dimen}$;\5
$\\{arith\_error}\K\\{false}$;\6
\&{end}\par
\U section~448\*.\fi

\M461. The final member of \TeX's value-scanning trio is \\{scan\_glue}, which
makes \\{cur\_val} point to a glue specification. The reference count of that
glue spec will take account of the fact that \\{cur\_val} is pointing to~it.

The \\{level} parameter should be either \\{glue\_val} or \\{mu\_val}.

Since \\{scan\_dimen} was so much more complex than \\{scan\_int}, we might
expect
\\{scan\_glue} to be even worse. But fortunately, it is very simple, since
most of the work has already been done for us.

\Y\P\4\&{procedure}\1\  \37$\\{scan\_glue}(\\{level}:\\{small\_number})$;%
\C{sets \\{cur\_val} to a glue spec pointer}\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37\\{negative}: \37\\{boolean};\C{should the answer be negated?}\6
\|q: \37\\{pointer};\C{new glue specification}\6
\\{mu}: \37\\{boolean};\C{does $\\{level}=\\{mu\_val}$?}\2\6
\&{begin} \37$\\{mu}\K(\\{level}=\\{mu\_val})$;\5
\X441:Get the next non-blank non-sign token; set \\{negative} appropriately\X;\6
\&{if} $(\\{cur\_cmd}\G\\{min\_internal})\W(\\{cur\_cmd}\L\\{max\_internal})$ %
\1\&{then}\6
\&{begin} \37$\\{scan\_something\_internal}(\\{level},\39\\{negative})$;\6
\&{if} $\\{cur\_val\_level}\G\\{glue\_val}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{cur\_val\_level}\I\\{level}$ \1\&{then}\5
\\{mu\_error};\2\6
\&{return};\6
\&{end};\2\6
\&{if} $\\{cur\_val\_level}=\\{int\_val}$ \1\&{then}\5
$\\{scan\_dimen}(\\{mu},\39\\{false},\39\\{true})$\6
\4\&{else} \&{if} $\\{level}=\\{mu\_val}$ \1\&{then}\5
\\{mu\_error};\2\2\6
\&{end}\6
\4\&{else} \&{begin} \37\\{back\_input};\5
$\\{scan\_dimen}(\\{mu},\39\\{false},\39\\{false})$;\6
\&{if} $\\{negative}$ \1\&{then}\5
$\\{negate}(\\{cur\_val})$;\2\6
\&{end};\2\6
\X462:Create a new glue specification whose width is \\{cur\_val}; scan for its
stretch and shrink components\X;\6
\4\\{exit}: \37\&{end};\par
\fi

\M462. \P$\X462:Create a new glue specification whose width is \\{cur\_val};
scan for its stretch and shrink components\X\S$\6
$\|q\K\\{new\_spec}(\\{zero\_glue})$;\5
$\\{width}(\|q)\K\\{cur\_val}$;\6
\&{if} $\\{scan\_keyword}(\.{"plus"})$ \1\&{then}\6
\&{begin} \37$\\{scan\_dimen}(\\{mu},\39\\{true},\39\\{false})$;\5
$\\{stretch}(\|q)\K\\{cur\_val}$;\5
$\\{stretch\_order}(\|q)\K\\{cur\_order}$;\6
\&{end};\2\6
\&{if} $\\{scan\_keyword}(\.{"minus"})$ \1\&{then}\6
\&{begin} \37$\\{scan\_dimen}(\\{mu},\39\\{true},\39\\{false})$;\5
$\\{shrink}(\|q)\K\\{cur\_val}$;\5
$\\{shrink\_order}(\|q)\K\\{cur\_order}$;\6
\&{end};\2\6
$\\{cur\_val}\K\|q$\par
\U section~461.\fi

\M463. Here's a similar procedure that returns a pointer to a rule node. This
routine is called just after \TeX\ has seen \.{\\hrule} or \.{\\vrule};
therefore \\{cur\_cmd} will be either \\{hrule} or \\{vrule}. The idea is to
store
the default rule dimensions in the node, then to override them if
`\.{height}' or `\.{width}' or `\.{depth}' specifications are
found (in any order).

\Y\P\D \37$\\{default\_rule}=26214$\C{0.4\thinspace pt}\par
\Y\P\4\&{function}\1\  \37\\{scan\_rule\_spec}: \37\\{pointer};\6
\4\&{label} \37\\{reswitch};\6
\4\&{var} \37\|q: \37\\{pointer};\C{the rule node being created}\2\6
\&{begin} \37$\|q\K\\{new\_rule}$;\C{\\{width}, \\{depth}, and \\{height} all
equal \\{null\_flag} now}\6
\&{if} $\\{cur\_cmd}=\\{vrule}$ \1\&{then}\5
$\\{width}(\|q)\K\\{default\_rule}$\6
\4\&{else} \&{begin} \37$\\{height}(\|q)\K\\{default\_rule}$;\5
$\\{depth}(\|q)\K0$;\6
\&{end};\2\6
\4\\{reswitch}: \37\&{if} $\\{scan\_keyword}(\.{"width"})$ \1\&{then}\6
\&{begin} \37\\{scan\_normal\_dimen};\5
$\\{width}(\|q)\K\\{cur\_val}$;\5
\&{goto} \37\\{reswitch};\6
\&{end};\2\6
\&{if} $\\{scan\_keyword}(\.{"height"})$ \1\&{then}\6
\&{begin} \37\\{scan\_normal\_dimen};\5
$\\{height}(\|q)\K\\{cur\_val}$;\5
\&{goto} \37\\{reswitch};\6
\&{end};\2\6
\&{if} $\\{scan\_keyword}(\.{"depth"})$ \1\&{then}\6
\&{begin} \37\\{scan\_normal\_dimen};\5
$\\{depth}(\|q)\K\\{cur\_val}$;\5
\&{goto} \37\\{reswitch};\6
\&{end};\2\6
$\\{scan\_rule\_spec}\K\|q$;\6
\&{end};\par
\fi

\N464.  \[27] Building token lists.
The token lists for macros and for other things like \.{\\mark} and \.{%
\\output}
and \.{\\write} are produced by a procedure called \\{scan\_toks}.

Before we get into the details of \\{scan\_toks}, let's consider a much
simpler task, that of converting the current string into a token list.
The \\{str\_toks} function does this; it classifies spaces as type \\{spacer}
and everything else as type \\{other\_char}.

The token list created by \\{str\_toks} begins at $\\{link}(\\{temp\_head})$
and ends
at the value \|p that is returned. (If $\|p=\\{temp\_head}$, the list is
empty.)

\Y\P\4\&{function}\1\  \37\\{str\_toks}: \37\\{pointer};\C{changes the current
string to a token list}\6
\4\&{var} \37\|p: \37\\{pointer};\C{tail of the token list}\6
\|q: \37\\{pointer};\C{new node being added to the token list via \\{store\_new%
\_token}}\6
\|t: \37\\{halfword};\C{token being appended}\6
\|k: \37\\{pool\_pointer};\C{index into \\{str\_pool}}\2\6
\&{begin} \37$\\{str\_room}(1)$;\5
$\|p\K\\{temp\_head}$;\5
$\\{link}(\|p)\K\\{null}$;\5
$\|k\K\\{str\_start}[\\{str\_ptr}]$;\6
\&{while} $\|k<\\{pool\_ptr}$ \1\&{do}\6
\&{begin} \37$\|t\K\\{str\_pool}[\|k]$;\6
\&{if} $\|t=\.{"\ "}$ \1\&{then}\5
$\|t\K\\{space\_token}$\6
\4\&{else} $\|t\K\\{other\_token}+\|t$;\2\6
$\\{fast\_store\_new\_token}(\|t)$;\5
$\\{incr}(\|k)$;\6
\&{end};\2\6
$\\{pool\_ptr}\K\\{str\_start}[\\{str\_ptr}]$;\5
$\\{str\_toks}\K\|p$;\6
\&{end};\par
\fi

\M465. The main reason for wanting \\{str\_toks} is the next function,
\\{the\_toks}, which has similar input/output characteristics.
This procedure is supposed to scan something like `\.{\\skip\\count12}',
i.e., whatever can follow `\.{\\the}', and it constructs a token list
containing something like `\.{-3.0pt minus 0.5fill}'.

\Y\P\4\&{function}\1\  \37\\{the\_toks}: \37\\{pointer};\6
\4\&{var} \37\\{old\_setting}: \37$0\to\\{max\_selector}$;\C{holds \\{selector}
setting}\6
$\|p,\39\|q,\39\|r$: \37\\{pointer};\C{used for copying a token list}\2\6
\&{begin} \37\\{get\_x\_token};\5
$\\{scan\_something\_internal}(\\{tok\_val},\39\\{false})$;\6
\&{if} $\\{cur\_val\_level}\G\\{ident\_val}$ \1\&{then}\5
\X466:Copy the token list\X\6
\4\&{else} \&{begin} \37$\\{old\_setting}\K\\{selector}$;\5
$\\{selector}\K\\{new\_string}$;\6
\&{case} $\\{cur\_val\_level}$ \1\&{of}\6
\4\\{int\_val}: \37$\\{print\_int}(\\{cur\_val})$;\6
\4\\{dimen\_val}: \37\&{begin} \37$\\{print\_scaled}(\\{cur\_val})$;\5
$\\{print}(\.{"pt"})$;\6
\&{end};\6
\4\\{glue\_val}: \37\&{begin} \37$\\{print\_spec}(\\{cur\_val},\39\.{"pt"})$;\5
$\\{delete\_glue\_ref}(\\{cur\_val})$;\6
\&{end};\6
\4\\{mu\_val}: \37\&{begin} \37$\\{print\_spec}(\\{cur\_val},\39\.{"mu"})$;\5
$\\{delete\_glue\_ref}(\\{cur\_val})$;\6
\&{end};\2\6
\&{end};\C{there are no other cases}\6
$\\{selector}\K\\{old\_setting}$;\5
$\\{the\_toks}\K\\{str\_toks}$;\6
\&{end};\2\6
\&{end};\par
\fi

\M466. \P$\X466:Copy the token list\X\S$\6
\&{begin} \37$\|p\K\\{temp\_head}$;\5
$\\{link}(\|p)\K\\{null}$;\6
\&{if} $\\{cur\_val\_level}=\\{ident\_val}$ \1\&{then}\5
$\\{store\_new\_token}(\\{cs\_token\_flag}+\\{cur\_val})$\6
\4\&{else} \&{if} $\\{cur\_val}\I\\{null}$ \1\&{then}\6
\&{begin} \37$\|r\K\\{link}(\\{cur\_val})$;\C{do not copy the reference count}\6
\&{while} $\|r\I\\{null}$ \1\&{do}\6
\&{begin} \37$\\{fast\_store\_new\_token}(\\{info}(\|r))$;\5
$\|r\K\\{link}(\|r)$;\6
\&{end};\2\6
\&{end};\2\2\6
$\\{the\_toks}\K\|p$;\6
\&{end}\par
\U section~465.\fi

\M467. Here's part of the \\{expand} subroutine that we are now ready to
complete:

\Y\P\4\&{procedure}\1\  \37\\{ins\_the\_toks};\2\6
\&{begin} \37$\\{link}(\\{garbage})\K\\{the\_toks}$;\5
$\\{ins\_list}(\\{link}(\\{temp\_head}))$;\6
\&{end};\par
\fi

\M468. The primitives \.{\\number}, \.{\\romannumeral}, \.{\\string}, \.{%
\\meaning},
\.{\\fontname}, and \.{\\jobname} are defined as follows.

\Y\P\D \37$\\{number\_code}=0$\C{command code for \.{\\number}}\par
\P\D \37$\\{roman\_numeral\_code}=1$\C{command code for \.{\\romannumeral}}\par
\P\D \37$\\{string\_code}=2$\C{command code for \.{\\string}}\par
\P\D \37$\\{meaning\_code}=3$\C{command code for \.{\\meaning}}\par
\P\D \37$\\{font\_name\_code}=4$\C{command code for \.{\\fontname}}\par
\P\D \37$\\{job\_name\_code}=5$\C{command code for \.{\\jobname}}\par
\Y\P$\4\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}\S$\6
$\\{primitive}(\.{"number"},\39\\{convert},\39\\{number\_code})$;\6
$\\{primitive}(\.{"romannumeral"},\39\\{convert},\39\\{roman\_numeral\_code})$;%
\6
$\\{primitive}(\.{"string"},\39\\{convert},\39\\{string\_code})$;\6
$\\{primitive}(\.{"meaning"},\39\\{convert},\39\\{meaning\_code})$;\6
$\\{primitive}(\.{"fontname"},\39\\{convert},\39\\{font\_name\_code})$;\6
$\\{primitive}(\.{"jobname"},\39\\{convert},\39\\{job\_name\_code})$;\par
\fi

\M469. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{convert}: \37\&{case} $\\{chr\_code}$ \1\&{of}\6
\4\\{number\_code}: \37$\\{print\_esc}(\.{"number"})$;\6
\4\\{roman\_numeral\_code}: \37$\\{print\_esc}(\.{"romannumeral"})$;\6
\4\\{string\_code}: \37$\\{print\_esc}(\.{"string"})$;\6
\4\\{meaning\_code}: \37$\\{print\_esc}(\.{"meaning"})$;\6
\4\\{font\_name\_code}: \37$\\{print\_esc}(\.{"fontname"})$;\6
\4\&{othercases} \37$\\{print\_esc}(\.{"jobname"})$\2\6
\&{endcases};\par
\fi

\M470. The procedure \\{conv\_toks} uses \\{str\_toks} to insert the token list
for \\{convert} functions into the scanner; `\.{\\outer}' control sequences
are allowed to follow `\.{\\string}' and `\.{\\meaning}'.

\Y\P\4\&{procedure}\1\  \37\\{conv\_toks};\6
\4\&{var} \37\\{old\_setting}: \37$0\to\\{max\_selector}$;\C{holds \\{selector}
setting}\6
\|c: \37$\\{number\_code}\to\\{job\_name\_code}$;\C{desired type of conversion}%
\6
\\{save\_scanner\_status}: \37\\{small\_number};\C{\\{scanner\_status} upon
entry}\2\6
\&{begin} \37$\|c\K\\{cur\_chr}$;\5
\X471:Scan the argument for command \|c\X;\6
$\\{old\_setting}\K\\{selector}$;\5
$\\{selector}\K\\{new\_string}$;\5
\X472:Print the result of command \|c\X;\6
$\\{selector}\K\\{old\_setting}$;\5
$\\{link}(\\{garbage})\K\\{str\_toks}$;\5
$\\{ins\_list}(\\{link}(\\{temp\_head}))$;\6
\&{end};\par
\fi

\M471. \P$\X471:Scan the argument for command \|c\X\S$\6
\&{case} $\|c$ \1\&{of}\6
\4$\\{number\_code},\39\\{roman\_numeral\_code}$: \37\\{scan\_int};\6
\4$\\{string\_code},\39\\{meaning\_code}$: \37\&{begin} \37$\\{save\_scanner%
\_status}\K\\{scanner\_status}$;\5
$\\{scanner\_status}\K\\{normal}$;\5
\\{get\_token};\5
$\\{scanner\_status}\K\\{save\_scanner\_status}$;\6
\&{end};\6
\4\\{font\_name\_code}: \37\\{scan\_font\_ident};\6
\4\\{job\_name\_code}: \37\&{if} $\\{job\_name}=0$ \1\&{then}\5
\\{open\_log\_file};\2\2\6
\&{end}\C{there are no other cases}\par
\U section~470.\fi

\M472. \P$\X472:Print the result of command \|c\X\S$\6
\&{case} $\|c$ \1\&{of}\6
\4\\{number\_code}: \37$\\{print\_int}(\\{cur\_val})$;\6
\4\\{roman\_numeral\_code}: \37$\\{print\_roman\_int}(\\{cur\_val})$;\6
\4\\{string\_code}: \37\&{if} $\\{cur\_cs}\I0$ \1\&{then}\5
$\\{sprint\_cs}(\\{cur\_cs})$\6
\4\&{else} $\\{print\_char}(\\{cur\_chr})$;\2\6
\4\\{meaning\_code}: \37\\{print\_meaning};\6
\4\\{font\_name\_code}: \37\&{begin} \37$\\{print}(\\{font\_name}[\\{cur%
\_val}])$;\6
\&{if} $\\{font\_size}[\\{cur\_val}]\I\\{font\_dsize}[\\{cur\_val}]$ \1\&{then}%
\6
\&{begin} \37$\\{print}(\.{"\ at\ "})$;\5
$\\{print\_scaled}(\\{font\_size}[\\{cur\_val}])$;\5
$\\{print}(\.{"pt"})$;\6
\&{end};\2\6
\&{end};\6
\4\\{job\_name\_code}: \37$\\{print}(\\{job\_name})$;\2\6
\&{end}\C{there are no other cases}\par
\U section~470.\fi

\M473. Now we can't postpone the difficulties any longer; we must bravely
tackle
\\{scan\_toks}. This function returns a pointer to the tail of a new token
list, and it also makes \\{def\_ref} point to the reference count at the
head of that list.

There are two boolean parameters, \\{macro\_def} and \\{xpand}. If \\{macro%
\_def}
is true, the goal is to create the token list for a macro definition;
otherwise the goal is to create the token list for some other \TeX\
primitive: \.{\\mark}, \.{\\output}, \.{\\everypar}, \.{\\lowercase},
\.{\\uppercase}, \.{\\message}, \.{\\errmessage}, \.{\\write}, or
\.{\\special}. In the latter cases a left brace must be scanned next; this
left brace will not be part of the token list, nor will the matching right
brace that comes at the end. If \\{xpand} is false, the token list will
simply be copied from the input using \\{get\_token}. Otherwise all expandable
tokens will be expanded until unexpandable tokens are left, except that
the results of expanding `\.{\\the}' are not expanded further.
If both \\{macro\_def} and \\{xpand} are true, the expansion applies
only to the macro body (i.e., to the material following the first
\\{left\_brace} character).

The value of \\{cur\_cs} when \\{scan\_toks} begins should be the \\{eqtb}
address of the control sequence to display in ``runaway'' error
messages.

\Y\P\4\&{function}\1\  \37$\\{scan\_toks}(\\{macro\_def},\39\\{xpand}:%
\\{boolean})$: \37\\{pointer};\6
\4\&{label} \37$\\{found},\39\\{done},\39\\{done1},\39\\{done2}$;\6
\4\&{var} \37\|t: \37\\{halfword};\C{token representing the highest parameter
number}\6
\|s: \37\\{halfword};\C{saved token}\6
\|p: \37\\{pointer};\C{tail of the token list being built}\6
\|q: \37\\{pointer};\C{new node being added to the token list via \\{store\_new%
\_token}}\6
\\{unbalance}: \37\\{halfword};\C{number of unmatched left braces}\6
\\{hash\_brace}: \37\\{halfword};\C{possible `\.{\#\{}' token}\2\6
\&{begin} \37\&{if} $\\{macro\_def}$ \1\&{then}\5
$\\{scanner\_status}\K\\{defining}$\ \&{else} $\\{scanner\_status}\K%
\\{absorbing}$;\2\6
$\\{warning\_index}\K\\{cur\_cs}$;\5
$\\{def\_ref}\K\\{get\_avail}$;\5
$\\{token\_ref\_count}(\\{def\_ref})\K\\{null}$;\5
$\|p\K\\{def\_ref}$;\5
$\\{hash\_brace}\K0$;\5
$\|t\K\\{zero\_token}$;\6
\&{if} $\\{macro\_def}$ \1\&{then}\5
\X474:Scan and build the parameter part of the macro definition\X\6
\4\&{else} \\{scan\_left\_brace};\C{remove the compulsory left brace}\2\6
\X477:Scan and build the body of the token list; \&{goto} \\{found} when
finished\X;\6
\4\\{found}: \37$\\{scanner\_status}\K\\{normal}$;\6
\&{if} $\\{hash\_brace}\I0$ \1\&{then}\5
$\\{store\_new\_token}(\\{hash\_brace})$;\2\6
$\\{scan\_toks}\K\|p$;\6
\&{end};\par
\fi

\M474. \P$\X474:Scan and build the parameter part of the macro definition\X\S$\6
\&{begin} \37\~ \1\&{loop}\6
\&{begin} \37\\{get\_token};\C{set \\{cur\_cmd}, \\{cur\_chr}, \\{cur\_tok}}\6
\&{if} $\\{cur\_tok}<\\{right\_brace\_limit}$ \1\&{then}\5
\&{goto} \37\\{done1};\2\6
\&{if} $\\{cur\_cmd}=\\{mac\_param}$ \1\&{then}\5
\X476:If the next character is a parameter number, make \\{cur\_tok} a %
\\{match} token; but if it is a left brace, store `\\{left\_brace}, \\{end%
\_match}', set \\{hash\_brace}, and \&{goto} \\{done}\X;\2\6
$\\{store\_new\_token}(\\{cur\_tok})$;\6
\&{end};\2\6
\4\\{done1}: \37$\\{store\_new\_token}(\\{end\_match\_token})$;\6
\&{if} $\\{cur\_cmd}=\\{right\_brace}$ \1\&{then}\5
\X475:Express shock at the missing left brace; \&{goto} \\{found}\X;\2\6
\4\\{done}: \37\&{end}\par
\U section~473.\fi

\M475. \P$\X475:Express shock at the missing left brace; \&{goto} \\{found}\X%
\S$\6
\&{begin} \37$\\{print\_err}(\.{"Missing\ \{\ inserted"})$;\5
$\\{incr}(\\{align\_state})$;\5
$\\{help2}(\.{"Where\ was\ the\ left\ brace?\ You\ said\ something\ like\ \`%
\\def\\a\}\',"})$\6
$(\.{"which\ I\'m\ going\ to\ interpret\ as\ \`\\def\\a\{\}\'."})$;\5
\\{error};\5
\&{goto} \37\\{found};\6
\&{end}\par
\U section~474.\fi

\M476. \P$\X476:If the next character is a parameter number, make \\{cur\_tok}
a \\{match} token; but if it is a left brace, store `\\{left\_brace}, \\{end%
\_match}', set \\{hash\_brace}, and \&{goto} \\{done}\X\S$\6
\&{begin} \37$\|s\K\\{match\_token}+\\{cur\_chr}$;\5
\\{get\_token};\6
\&{if} $\\{cur\_cmd}=\\{left\_brace}$ \1\&{then}\6
\&{begin} \37$\\{hash\_brace}\K\\{cur\_tok}$;\5
$\\{store\_new\_token}(\\{cur\_tok})$;\5
$\\{store\_new\_token}(\\{end\_match\_token})$;\5
\&{goto} \37\\{done};\6
\&{end};\2\6
\&{if} $\|t=\\{zero\_token}+9$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"You\ already\ have\ nine\ parameters"})$;\5
$\\{help1}(\.{"I\'m\ going\ to\ ignore\ the\ \#\ sign\ you\ just\ used."})$;\5
\\{error};\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{incr}(\|t)$;\6
\&{if} $\\{cur\_tok}\I\|t$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Parameters\ must\ be\ numbered\
consecutively"})$;\5
$\\{help2}(\.{"I\'ve\ inserted\ the\ digit\ you\ should\ have\ used\ after\ the%
\ \#."})$\6
$(\.{"Type\ \`1\'\ to\ delete\ what\ you\ did\ use."})$;\5
\\{back\_error};\6
\&{end};\2\6
$\\{cur\_tok}\K\|s$;\6
\&{end};\2\6
\&{end}\par
\U section~474.\fi

\M477. \P$\X477:Scan and build the body of the token list; \&{goto} \\{found}
when finished\X\S$\6
$\\{unbalance}\K1$;\6
\~ \1\&{loop}\ \&{begin} \37\&{if} $\\{xpand}$ \1\&{then}\5
\X478:Expand the next part of the input\X\6
\4\&{else} \\{get\_token};\2\6
\&{if} $\\{cur\_tok}<\\{right\_brace\_limit}$ \1\&{then}\6
\&{if} $\\{cur\_cmd}<\\{right\_brace}$ \1\&{then}\5
$\\{incr}(\\{unbalance})$\6
\4\&{else} \&{begin} \37$\\{decr}(\\{unbalance})$;\6
\&{if} $\\{unbalance}=0$ \1\&{then}\5
\&{goto} \37\\{found};\2\6
\&{end}\2\6
\4\&{else} \&{if} $\\{cur\_cmd}=\\{mac\_param}$ \1\&{then}\6
\&{if} $\\{macro\_def}$ \1\&{then}\5
\X479:Look for parameter number or \.{\#\#}\X;\2\2\2\6
$\\{store\_new\_token}(\\{cur\_tok})$;\6
\&{end}\2\par
\U section~473.\fi

\M478. Here we insert an entire token list created by \\{the\_toks} without
expanding it further.

\Y\P$\4\X478:Expand the next part of the input\X\S$\6
\&{begin} \37\~ \1\&{loop}\6
\&{begin} \37\\{get\_next};\6
\&{if} $\\{cur\_cmd}\L\\{max\_command}$ \1\&{then}\5
\&{goto} \37\\{done2};\2\6
\&{if} $\\{cur\_cmd}\I\\{the}$ \1\&{then}\5
\\{expand}\6
\4\&{else} \&{begin} \37$\|q\K\\{the\_toks}$;\6
\&{if} $\\{link}(\\{temp\_head})\I\\{null}$ \1\&{then}\6
\&{begin} \37$\\{link}(\|p)\K\\{link}(\\{temp\_head})$;\5
$\|p\K\|q$;\6
\&{end};\2\6
\&{end};\2\6
\&{end};\2\6
\4\\{done2}: \37\\{x\_token}\6
\&{end}\par
\U section~477.\fi

\M479. \P$\X479:Look for parameter number or \.{\#\#}\X\S$\6
\&{begin} \37$\|s\K\\{cur\_tok}$;\6
\&{if} $\\{xpand}$ \1\&{then}\5
\\{get\_x\_token}\6
\4\&{else} \\{get\_token};\2\6
\&{if} $\\{cur\_cmd}\I\\{mac\_param}$ \1\&{then}\6
\&{if} $(\\{cur\_tok}\L\\{zero\_token})\V(\\{cur\_tok}>\|t)$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Illegal\ parameter\ number\ in\ definition\ of%
\ "})$;\5
$\\{sprint\_cs}(\\{warning\_index})$;\5
$\\{help3}(\.{"You\ meant\ to\ type\ \#\#\ instead\ of\ \#,\ right?"})$\6
$(\.{"Or\ maybe\ a\ \}\ was\ forgotten\ somewhere\ earlier,\ and\ things"})$\6
$(\.{"are\ all\ screwed\ up?\ I\'m\ going\ to\ assume\ that\ you\ meant\ \#%
\#."})$;\5
\\{back\_error};\5
$\\{cur\_tok}\K\|s$;\6
\&{end}\6
\4\&{else} $\\{cur\_tok}\K\\{out\_param\_token}-\.{"0"}+\\{cur\_chr}$;\2\2\6
\&{end}\par
\U section~477.\fi

\M480. Another way to create a token list is via the \.{\\read} command. The
sixteen files potentially usable for reading appear in the following
global variables. The value of $\\{read\_open}[\|n]$ will be \\{closed} if
stream number \|n has not been opened or if it has been fully read;
\\{just\_open} if an \.{\\openin} but not a \.{\\read} has been done;
and \\{normal} if it is open and ready to read the next line.

\Y\P\D \37$\\{closed}=2$\C{not open, or at end of file}\par
\P\D \37$\\{just\_open}=1$\C{newly opened, first line not yet read}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{read\_file}: \37\&{array} $[0\to15]$ \1\&{of}\5
\\{alpha\_file};\C{used for \.{\\read}}\2\6
\4\\{read\_open}: \37\&{array} $[0\to16]$ \1\&{of}\5
$\\{normal}\to\\{closed}$;\C{state of $\\{read\_file}[\|n]$}\2\par
\fi

\M481. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
\&{for} $\|k\K0\mathrel{\&{to}}16$ \1\&{do}\5
$\\{read\_open}[\|k]\K\\{closed}$;\2\par
\fi

\M482. The \\{read\_toks} procedure constructs a token list like that for any
macro definition, and makes \\{cur\_val} point to it. Parameter \|r points
to the control sequence that will receive this token list.

\Y\P\4\&{procedure}\1\  \37$\\{read\_toks}(\|n:\\{integer};\,\35\|r:%
\\{pointer})$;\6
\4\&{label} \37\\{done};\6
\4\&{var} \37\|p: \37\\{pointer};\C{tail of the token list}\6
\|q: \37\\{pointer};\C{new node being added to the token list via \\{store\_new%
\_token}}\6
\|s: \37\\{integer};\C{saved value of \\{align\_state}}\6
\|m: \37\\{small\_number};\C{stream number}\2\6
\&{begin} \37$\\{scanner\_status}\K\\{defining}$;\5
$\\{warning\_index}\K\|r$;\5
$\\{def\_ref}\K\\{get\_avail}$;\5
$\\{token\_ref\_count}(\\{def\_ref})\K\\{null}$;\5
$\|p\K\\{def\_ref}$;\C{the reference count}\6
$\\{store\_new\_token}(\\{end\_match\_token})$;\6
\&{if} $(\|n<0)\V(\|n>15)$ \1\&{then}\5
$\|m\K16$\ \&{else} $\|m\K\|n$;\2\6
$\|s\K\\{align\_state}$;\5
$\\{align\_state}\K1000000$;\C{disable tab marks, etc.}\6
\1\&{repeat} \37\X483:Input and store tokens from the next line of the file\X;\6
\4\&{until}\5
$\\{align\_state}=1000000$;\2\6
$\\{cur\_val}\K\\{def\_ref}$;\5
$\\{scanner\_status}\K\\{normal}$;\5
$\\{align\_state}\K\|s$;\6
\&{end};\par
\fi

\M483. \P$\X483:Input and store tokens from the next line of the file\X\S$\6
\\{begin\_file\_reading};\5
$\\{name}\K\|m+1$;\6
\&{if} $\\{read\_open}[\|m]=\\{closed}$ \1\&{then}\5
\X484:Input for \.{\\read} from the terminal\X\6
\4\&{else} \&{if} $\\{read\_open}[\|m]=\\{just\_open}$ \1\&{then}\5
\X485\*:Input the first line of $\\{read\_file}[\|m]$\X\6
\4\&{else} \X486:Input the next line of $\\{read\_file}[\|m]$\X;\2\2\6
$\\{limit}\K\\{last}$;\6
\&{if} $(\\{end\_line\_char}<0)\V(\\{end\_line\_char}>127)$ \1\&{then}\5
$\\{decr}(\\{limit})$\6
\4\&{else} $\\{buffer}[\\{limit}]\K\\{end\_line\_char}$;\2\6
$\\{first}\K\\{limit}+1$;\5
$\\{loc}\K\\{start}$;\5
$\\{state}\K\\{new\_line}$;\6
\~ \1\&{loop}\ \&{begin} \37\\{get\_token};\6
\&{if} $\\{cur\_tok}=0$ \1\&{then}\5
\&{goto} \37\\{done};\C{$\\{cur\_cmd}=\\{cur\_chr}=0$ will occur at the end of
the line}\2\6
$\\{store\_new\_token}(\\{cur\_tok})$;\6
\&{end};\2\6
\4\\{done}: \37\\{end\_file\_reading}\par
\U section~482.\fi

\M484. Here we input on-line into the \\{buffer} array, prompting the user
explicitly
if $\|n\G0$.  The value of \|n is set negative so that additional prompts
will not be given in the case of multi-line input.

\Y\P$\4\X484:Input for \.{\\read} from the terminal\X\S$\6
\&{if} $\\{interaction}>\\{nonstop\_mode}$ \1\&{then}\6
\&{if} $\|n<0$ \1\&{then}\5
$\\{prompt\_input}(\.{""})$\6
\4\&{else} \&{begin} \37\\{wake\_up\_terminal};\5
\\{print\_ln};\5
$\\{sprint\_cs}(\|r)$;\5
$\\{prompt\_input}(\.{"="})$;\5
$\|n\K-1$;\6
\&{end}\2\6
\4\&{else} $\\{fatal\_error}(\.{"***\ (cannot\ \\read\ from\ terminal\ in\
nonstop\ modes)"})$\2\par
\U section~483.\fi

\M485\*. The first line of a file must be treated specially, since \\{input%
\_ln}
must be told not to \\{get}. Furthermore we want to omit the optional file
directory page present at {\mc SAIL}.

\Y\P$\4\X485\*:Input the first line of $\\{read\_file}[\|m]$\X\S$\6
\&{if} $\R\\{input\_ln}(\\{read\_file}[\|m],\39\\{false})$ \1\&{then}\6
\&{begin} \37$\\{a\_close}(\\{read\_file}[\|m])$;\5
$\\{read\_open}[\|m]\K\\{closed}$;\6
\&{end}\6
\4\&{else} \&{begin} \37\&{if} $(\\{last}-\\{start}=29)\W(\\{buffer}[%
\\{start}]=\.{"C"})\W(\\{buffer}[\\{start}+8]=\O{26})$ \1\&{then}\6
\&{begin} \37\&{while} $(\\{read\_file}[\|m]\↑\I\\{chr}(\\{form\_feed}))\W(\R%
\\{eof}(\\{read\_file}[\|m]))$ \1\&{do}\6
\&{begin} \37$\\{read\_ln}(\\{read\_file}[\|m])$;\5
$\\{read}(\\{read\_file}[\|m],\39\\{aux\_buf}:\\{temp\_ptr})$;\6
\&{end};\C{skip the directory}\2\6
$\\{buffer}[\\{start}]\K\\{form\_feed}$;\5
$\\{last}\K\\{start}+1$;\6
\&{end};\2\6
$\\{read\_open}[\|m]\K\\{normal}$;\6
\&{end}\2\par
\U section~483.\fi

\M486. An empty line is appended at the end of a \\{read\_file}.

\Y\P$\4\X486:Input the next line of $\\{read\_file}[\|m]$\X\S$\6
\&{begin} \37\&{if} $\R\\{input\_ln}(\\{read\_file}[\|m],\39\\{true})$ \1%
\&{then}\6
\&{begin} \37$\\{a\_close}(\\{read\_file}[\|m])$;\5
$\\{read\_open}[\|m]\K\\{closed}$;\6
\&{if} $\\{align\_state}\I1000000$ \1\&{then}\6
\&{begin} \37\\{runaway};\5
$\\{print\_err}(\.{"File\ ended\ within\ "})$;\5
$\\{print\_esc}(\.{"read"})$;\5
$\\{help1}(\.{"This\ \\read\ has\ unbalanced\ braces."})$;\5
$\\{align\_state}\K1000000$;\5
\\{error};\6
\&{end};\2\6
\&{end};\2\6
\&{end}\par
\U section~483.\fi

\N487.  \[28] Conditional processing.
We consider now the way \TeX\ handles various kinds of \.{\\if} commands.

\Y\P\D \37$\\{if\_char\_code}=0$\C{ `\.{\\if}' }\par
\P\D \37$\\{if\_cat\_code}=1$\C{ `\.{\\ifcat}' }\par
\P\D \37$\\{if\_int\_code}=2$\C{ `\.{\\ifnum}' }\par
\P\D \37$\\{if\_dim\_code}=3$\C{ `\.{\\ifdim}' }\par
\P\D \37$\\{if\_odd\_code}=4$\C{ `\.{\\ifodd}' }\par
\P\D \37$\\{if\_vmode\_code}=5$\C{ `\.{\\ifvmode}' }\par
\P\D \37$\\{if\_hmode\_code}=6$\C{ `\.{\\ifhmode}' }\par
\P\D \37$\\{if\_mmode\_code}=7$\C{ `\.{\\ifmmode}' }\par
\P\D \37$\\{if\_inner\_code}=8$\C{ `\.{\\ifinner}' }\par
\P\D \37$\\{if\_void\_code}=9$\C{ `\.{\\ifvoid}' }\par
\P\D \37$\\{if\_hbox\_code}=10$\C{ `\.{\\ifhbox}' }\par
\P\D \37$\\{if\_vbox\_code}=11$\C{ `\.{\\ifvbox}' }\par
\P\D \37$\\{ifx\_code}=12$\C{ `\.{\\ifx}' }\par
\P\D \37$\\{if\_eof\_code}=13$\C{ `\.{\\ifeof}' }\par
\P\D \37$\\{if\_true\_code}=14$\C{ `\.{\\iftrue}' }\par
\P\D \37$\\{if\_false\_code}=15$\C{ `\.{\\iffalse}' }\par
\P\D \37$\\{if\_case\_code}=16$\C{ `\.{\\ifcase}' }\par
\Y\P$\4\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}\S$\6
$\\{primitive}(\.{"if"},\39\\{if\_test},\39\\{if\_char\_code})$;\5
$\\{primitive}(\.{"ifcat"},\39\\{if\_test},\39\\{if\_cat\_code})$;\5
$\\{primitive}(\.{"ifnum"},\39\\{if\_test},\39\\{if\_int\_code})$;\5
$\\{primitive}(\.{"ifdim"},\39\\{if\_test},\39\\{if\_dim\_code})$;\5
$\\{primitive}(\.{"ifodd"},\39\\{if\_test},\39\\{if\_odd\_code})$;\5
$\\{primitive}(\.{"ifvmode"},\39\\{if\_test},\39\\{if\_vmode\_code})$;\5
$\\{primitive}(\.{"ifhmode"},\39\\{if\_test},\39\\{if\_hmode\_code})$;\5
$\\{primitive}(\.{"ifmmode"},\39\\{if\_test},\39\\{if\_mmode\_code})$;\5
$\\{primitive}(\.{"ifinner"},\39\\{if\_test},\39\\{if\_inner\_code})$;\5
$\\{primitive}(\.{"ifvoid"},\39\\{if\_test},\39\\{if\_void\_code})$;\5
$\\{primitive}(\.{"ifhbox"},\39\\{if\_test},\39\\{if\_hbox\_code})$;\5
$\\{primitive}(\.{"ifvbox"},\39\\{if\_test},\39\\{if\_vbox\_code})$;\5
$\\{primitive}(\.{"ifx"},\39\\{if\_test},\39\\{ifx\_code})$;\5
$\\{primitive}(\.{"ifeof"},\39\\{if\_test},\39\\{if\_eof\_code})$;\5
$\\{primitive}(\.{"iftrue"},\39\\{if\_test},\39\\{if\_true\_code})$;\5
$\\{primitive}(\.{"iffalse"},\39\\{if\_test},\39\\{if\_false\_code})$;\5
$\\{primitive}(\.{"ifcase"},\39\\{if\_test},\39\\{if\_case\_code})$;\par
\fi

\M488. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{if\_test}: \37\&{case} $\\{chr\_code}$ \1\&{of}\6
\4\\{if\_cat\_code}: \37$\\{print\_esc}(\.{"ifcat"})$;\6
\4\\{if\_int\_code}: \37$\\{print\_esc}(\.{"ifnum"})$;\6
\4\\{if\_dim\_code}: \37$\\{print\_esc}(\.{"ifdim"})$;\6
\4\\{if\_odd\_code}: \37$\\{print\_esc}(\.{"ifodd"})$;\6
\4\\{if\_vmode\_code}: \37$\\{print\_esc}(\.{"ifvmode"})$;\6
\4\\{if\_hmode\_code}: \37$\\{print\_esc}(\.{"ifhmode"})$;\6
\4\\{if\_mmode\_code}: \37$\\{print\_esc}(\.{"ifmmode"})$;\6
\4\\{if\_inner\_code}: \37$\\{print\_esc}(\.{"ifinner"})$;\6
\4\\{if\_void\_code}: \37$\\{print\_esc}(\.{"ifvoid"})$;\6
\4\\{if\_hbox\_code}: \37$\\{print\_esc}(\.{"ifhbox"})$;\6
\4\\{if\_vbox\_code}: \37$\\{print\_esc}(\.{"ifvbox"})$;\6
\4\\{ifx\_code}: \37$\\{print\_esc}(\.{"ifx"})$;\6
\4\\{if\_eof\_code}: \37$\\{print\_esc}(\.{"ifeof"})$;\6
\4\\{if\_true\_code}: \37$\\{print\_esc}(\.{"iftrue"})$;\6
\4\\{if\_false\_code}: \37$\\{print\_esc}(\.{"iffalse"})$;\6
\4\\{if\_case\_code}: \37$\\{print\_esc}(\.{"ifcase"})$;\6
\4\&{othercases} \37$\\{print\_esc}(\.{"if"})$\2\6
\&{endcases};\par
\fi

\M489. Conditions can be inside conditions, and this nesting has a stack
that is independent of the \\{save\_stack}.

Four global variables represent the top of the condition stack:
\\{cond\_ptr} points to pushed-down entries, if any; \\{if\_limit} specifies
the largest code of a \\{fi\_or\_else} command that is syntactically legal;
\\{cur\_if} is the name of the current type of conditional; and \\{if\_line}
is the line number at which it began.

If no conditions are currently in progress, the condition stack has the
special state $\\{cond\_ptr}=\\{null}$, $\\{if\_limit}=\\{normal}$, $\\{cur%
\_if}=0$, $\\{if\_line}=0$.
Otherwise \\{cond\_ptr} points to a two-word node; the \\{type}, \\{subtype},
and
\\{link} fields of the first word contain \\{if\_limit}, \\{cur\_if}, and
\\{cond\_ptr} at the next level, and the second word contains the
corresponding \\{if\_line}.

\Y\P\D \37$\\{if\_node\_size}=2$\C{number of words in stack entry for
conditionals}\par
\P\D \37$\\{if\_line\_field}(\#)\S\\{mem}[\#+1].\\{int}$\par
\P\D \37$\\{if\_code}=1$\C{code for \.{\\if...} being evaluated}\par
\P\D \37$\\{fi\_code}=2$\C{code for \.{\\fi}}\par
\P\D \37$\\{else\_code}=3$\C{code for \.{\\else}}\par
\P\D \37$\\{or\_code}=4$\C{code for \.{\\or}}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{cond\_ptr}: \37\\{pointer};\C{top of the condition stack}\6
\4\\{if\_limit}: \37$\\{normal}\to\\{or\_code}$;\C{upper bound on \\{fi\_or%
\_else} codes}\6
\4\\{cur\_if}: \37\\{small\_number};\C{type of conditional being worked on}\6
\4\\{if\_line}: \37\\{integer};\C{line where that conditional began}\par
\fi

\M490. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{cond\_ptr}\K\\{null}$;\5
$\\{if\_limit}\K\\{normal}$;\5
$\\{cur\_if}\K0$;\5
$\\{if\_line}\K0$;\par
\fi

\M491. \P$\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}%
\S$\6
$\\{primitive}(\.{"fi"},\39\\{fi\_or\_else},\39\\{fi\_code})$;\5
$\\{text}(\\{frozen\_fi})\K\.{"fi"}$;\5
$\\{eqtb}[\\{frozen\_fi}]\K\\{eqtb}[\\{cur\_val}]$;\5
$\\{primitive}(\.{"or"},\39\\{fi\_or\_else},\39\\{or\_code})$;\5
$\\{primitive}(\.{"else"},\39\\{fi\_or\_else},\39\\{else\_code})$;\par
\fi

\M492. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{fi\_or\_else}: \37\&{if} $\\{chr\_code}=\\{fi\_code}$ \1\&{then}\5
$\\{print\_esc}(\.{"fi"})$\6
\4\&{else} \&{if} $\\{chr\_code}=\\{or\_code}$ \1\&{then}\5
$\\{print\_esc}(\.{"or"})$\6
\4\&{else} $\\{print\_esc}(\.{"else"})$;\2\2\par
\fi

\M493\*. When we skip conditional text, we keep track of the line number
where skipping began, for use in error messages. Also the page number.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4$\\{skip\_line},\39\\{skip\_page}$: \37\\{integer};\C{skipping began here}\par
\fi

\M494\*. Here is a procedure that ignores text until coming to an \.{\\or},
\.{\\else}, or \.{\\fi} at level zero of $\.{\\if}\ldots\.{\\fi}$
nesting. After it has acted, \\{cur\_chr} will indicate the token that
was found, but \\{cur\_tok} will not be set (because this makes the
procedure run faster).

\Y\P\4\&{procedure}\1\  \37\\{pass\_text};\6
\4\&{label} \37\\{done};\6
\4\&{var} \37\|l: \37\\{integer};\C{level of $\.{\\if}\ldots\.{\\fi}$ nesting}\6
\\{save\_scanner\_status}: \37\\{small\_number};\C{\\{scanner\_status} upon
entry}\2\6
\&{begin} \37$\\{save\_scanner\_status}\K\\{scanner\_status}$;\5
$\\{scanner\_status}\K\\{skipping}$;\5
$\|l\K0$;\5
$\\{skip\_line}\K\\{line}$;\5
$\\{skip\_page}\K\\{page}$;\6
\~ \1\&{loop}\ \&{begin} \37\\{get\_next};\6
\&{if} $\\{cur\_cmd}=\\{fi\_or\_else}$ \1\&{then}\6
\&{begin} \37\&{if} $\|l=0$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
\&{if} $\\{cur\_chr}=\\{fi\_code}$ \1\&{then}\5
$\\{decr}(\|l)$;\2\6
\&{end}\6
\4\&{else} \&{if} $\\{cur\_cmd}=\\{if\_test}$ \1\&{then}\5
$\\{incr}(\|l)$;\2\2\6
\&{end};\2\6
\4\\{done}: \37$\\{scanner\_status}\K\\{save\_scanner\_status}$;\6
\&{end};\par
\fi

\M495. When we begin to process a new \.{\\if}, we set $\\{if\_limit}\K\\{if%
\_code}$; then
if\/ \.{\\or} or \.{\\else} or \.{\\fi} occurs before the current \.{\\if}
condition has been evaluated, \.{\\relax} will be inserted.
For example, a sequence of commands like `\.{\\ifvoid1\\else...\\fi}'
would otherwise require something after the `\.1'.

\Y\P$\4\X495:Push the condition stack\X\S$\6
\&{begin} \37$\|p\K\\{get\_node}(\\{if\_node\_size})$;\5
$\\{link}(\|p)\K\\{cond\_ptr}$;\5
$\\{type}(\|p)\K\\{if\_limit}$;\5
$\\{subtype}(\|p)\K\\{cur\_if}$;\5
$\\{if\_line\_field}(\|p)\K\\{if\_line}$;\5
$\\{cond\_ptr}\K\|p$;\5
$\\{cur\_if}\K\\{cur\_chr}$;\5
$\\{if\_limit}\K\\{if\_code}$;\5
$\\{if\_line}\K\\{line}$;\6
\&{end}\par
\U section~498.\fi

\M496. \P$\X496:Pop the condition stack\X\S$\6
\&{begin} \37$\|p\K\\{cond\_ptr}$;\5
$\\{if\_line}\K\\{if\_line\_field}(\|p)$;\5
$\\{cur\_if}\K\\{subtype}(\|p)$;\5
$\\{if\_limit}\K\\{type}(\|p)$;\5
$\\{cond\_ptr}\K\\{link}(\|p)$;\5
$\\{free\_node}(\|p,\39\\{if\_node\_size})$;\6
\&{end}\par
\U sections~498, 500, 509, and~510.\fi

\M497. Here's a procedure that changes the \\{if\_limit} code corresponding to
a given value of \\{cond\_ptr}.

\Y\P\4\&{procedure}\1\  \37$\\{change\_if\_limit}(\|l:\\{small\_number};\,\35%
\|p:\\{pointer})$;\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37\|q: \37\\{pointer};\2\6
\&{begin} \37\&{if} $\|p=\\{cond\_ptr}$ \1\&{then}\5
$\\{if\_limit}\K\|l$\C{that's the easy case}\6
\4\&{else} \&{begin} \37$\|q\K\\{cond\_ptr}$;\6
\~ \1\&{loop}\ \&{begin} \37\&{if} $\|q=\\{null}$ \1\&{then}\5
$\\{confusion}(\.{"if"})$;\2\6
\&{if} $\\{link}(\|q)=\|p$ \1\&{then}\6
\&{begin} \37$\\{type}(\|q)\K\|l$;\5
\&{return};\6
\&{end};\2\6
$\|q\K\\{link}(\|q)$;\6
\&{end};\2\6
\&{end};\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M498. A condition is started when the \\{expand} procedure encounters
an \\{if\_test} command; in that case \\{expand} reduces to \\{conditional},
which is a recursive procedure.

\Y\P\4\&{procedure}\1\  \37\\{conditional};\6
\4\&{label} \37$\\{exit},\39\\{common\_ending}$;\6
\4\&{var} \37\|b: \37\\{boolean};\C{is the condition true?}\6
\|r: \37$\.{"<"}\to\.{">"}$;\C{relation to be evaluated}\6
$\|m,\39\|n$: \37\\{integer};\C{to be tested against the second operand}\6
$\|p,\39\|q$: \37\\{pointer};\C{for traversing token lists in \.{\\ifx} tests}\6
\\{save\_scanner\_status}: \37\\{small\_number};\C{\\{scanner\_status} upon
entry}\6
\\{save\_cond\_ptr}: \37\\{pointer};\C{\\{cond\_ptr} corresponding to this
conditional}\6
\\{this\_if}: \37\\{small\_number};\C{type of this conditional}\2\6
\&{begin} \37\X495:Push the condition stack\X;\ $\\{save\_cond\_ptr}\K\\{cond%
\_ptr}$;\5
$\\{this\_if}\K\\{cur\_chr}$;\6
\X501:Either process \.{\\ifcase} or set \|b to the value of a boolean
condition\X;\6
\&{if} $\\{tracing\_commands}>1$ \1\&{then}\5
\X502:Display the value of \|b\X;\2\6
\&{if} $\|b$ \1\&{then}\6
\&{begin} \37$\\{change\_if\_limit}(\\{else\_code},\39\\{save\_cond\_ptr})$;\5
\&{return};\C{wait for \.{\\else} or \.{\\fi}}\6
\&{end};\2\6
\X500:Skip to \.{\\else} or \.{\\fi}, then \&{goto} \\{common\_ending}\X;\6
\4\\{common\_ending}: \37\&{if} $\\{cur\_chr}=\\{fi\_code}$ \1\&{then}\5
\X496:Pop the condition stack\X\6
\4\&{else} $\\{if\_limit}\K\\{fi\_code}$;\C{wait for \.{\\fi}}\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M499. In a construction like `\.{\\if\\iftrue abc\\else d\\fi}', the first
\.{\\else} that we come to after learning that the \.{\\if} is false is
not the \.{\\else} we're looking for. Hence the following curious
logic is needed.

\fi

\M500. \P$\X500:Skip to \.{\\else} or \.{\\fi}, then \&{goto} \\{common%
\_ending}\X\S$\6
\~ \1\&{loop}\ \&{begin} \37\\{pass\_text};\6
\&{if} $\\{cond\_ptr}=\\{save\_cond\_ptr}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{cur\_chr}\I\\{or\_code}$ \1\&{then}\5
\&{goto} \37\\{common\_ending};\2\6
$\\{print\_err}(\.{"Extra\ "})$;\5
$\\{print\_esc}(\.{"or"})$;\5
$\\{help1}(\.{"I\'m\ ignoring\ this;\ it\ doesn\'t\ match\ any\ \\if."})$;\5
\\{error};\6
\&{end}\6
\4\&{else} \&{if} $\\{cur\_chr}=\\{fi\_code}$ \1\&{then}\5
\X496:Pop the condition stack\X;\2\2\6
\&{end}\2\par
\U section~498.\fi

\M501. \P$\X501:Either process \.{\\ifcase} or set \|b to the value of a
boolean condition\X\S$\6
\&{case} $\\{this\_if}$ \1\&{of}\6
\4$\\{if\_char\_code},\39\\{if\_cat\_code}$: \37\X506:Test if two characters
match\X;\6
\4$\\{if\_int\_code},\39\\{if\_dim\_code}$: \37\X503:Test relation between
integers or dimensions\X;\6
\4\\{if\_odd\_code}: \37\X504:Test if an integer is odd\X;\6
\4\\{if\_vmode\_code}: \37$\|b\K(\\{abs}(\\{mode})=\\{vmode})$;\6
\4\\{if\_hmode\_code}: \37$\|b\K(\\{abs}(\\{mode})=\\{hmode})$;\6
\4\\{if\_mmode\_code}: \37$\|b\K(\\{abs}(\\{mode})=\\{mmode})$;\6
\4\\{if\_inner\_code}: \37$\|b\K(\\{mode}<0)$;\6
\4$\\{if\_void\_code},\39\\{if\_hbox\_code},\39\\{if\_vbox\_code}$: \37%
\X505:Test box register status\X;\6
\4\\{ifx\_code}: \37\X507:Test if two tokens match\X;\6
\4\\{if\_eof\_code}: \37\&{begin} \37\\{scan\_four\_bit\_int};\5
$\|b\K(\\{read\_open}[\\{cur\_val}]=\\{closed})$;\6
\&{end};\6
\4\\{if\_true\_code}: \37$\|b\K\\{true}$;\6
\4\\{if\_false\_code}: \37$\|b\K\\{false}$;\6
\4\\{if\_case\_code}: \37\X509:Select the appropriate case and \&{return} or %
\&{goto} \\{common\_ending}\X;\2\6
\&{end}\C{there are no other cases}\par
\U section~498.\fi

\M502. \P$\X502:Display the value of \|b\X\S$\6
\&{begin} \37\\{begin\_diagnostic};\6
\&{if} $\|b$ \1\&{then}\5
$\\{print}(\.{"\{true\}"})$\ \&{else} $\\{print}(\.{"\{false\}"})$;\2\6
$\\{end\_diagnostic}(\\{false})$;\6
\&{end}\par
\U section~498.\fi

\M503. Here we use the fact that \.{"<"}, \.{"="}, and \.{">"} are consecutive
ASCII
codes.

\Y\P$\4\X503:Test relation between integers or dimensions\X\S$\6
\&{begin} \37\&{if} $\\{this\_if}=\\{if\_int\_code}$ \1\&{then}\5
\\{scan\_int}\ \&{else} \\{scan\_normal\_dimen};\2\6
$\|n\K\\{cur\_val}$;\5
\X406:Get the next non-blank non-call token\X;\6
\&{if} $(\\{cur\_tok}\G\\{other\_token}+\.{"<"})\W(\\{cur\_tok}\L\\{other%
\_token}+\.{">"})$ \1\&{then}\5
$\|r\K\\{cur\_tok}-\\{other\_token}$\6
\4\&{else} \&{begin} \37$\\{print\_err}(\.{"Missing\ =\ inserted\ for\ "})$;\5
$\\{print\_cmd\_chr}(\\{if\_test},\39\\{this\_if})$;\5
$\\{help1}(\.{"I\ was\ expecting\ to\ see\ \`<\',\ \`=\',\ or\ \`>\'.\ Didn%
\'t."})$;\5
\\{back\_error};\5
$\|r\K\.{"="}$;\6
\&{end};\2\6
\&{if} $\\{this\_if}=\\{if\_int\_code}$ \1\&{then}\5
\\{scan\_int}\ \&{else} \\{scan\_normal\_dimen};\2\6
\&{case} $\|r$ \1\&{of}\6
\4\.{"<"}: \37$\|b\K(\|n<\\{cur\_val})$;\6
\4\.{"="}: \37$\|b\K(\|n=\\{cur\_val})$;\6
\4\.{">"}: \37$\|b\K(\|n>\\{cur\_val})$;\2\6
\&{end};\6
\&{end}\par
\U section~501.\fi

\M504. \P$\X504:Test if an integer is odd\X\S$\6
\&{begin} \37\\{scan\_int};\5
$\|b\K\\{odd}(\\{cur\_val})$;\6
\&{end}\par
\U section~501.\fi

\M505. \P$\X505:Test box register status\X\S$\6
\&{begin} \37\\{scan\_eight\_bit\_int};\5
$\|p\K\\{box}(\\{cur\_val})$;\6
\&{if} $\\{this\_if}=\\{if\_void\_code}$ \1\&{then}\5
$\|b\K(\|p=\\{null})$\6
\4\&{else} \&{if} $\|p=\\{null}$ \1\&{then}\5
$\|b\K\\{false}$\6
\4\&{else} \&{if} $\\{this\_if}=\\{if\_hbox\_code}$ \1\&{then}\5
$\|b\K(\\{type}(\|p)=\\{hlist\_node})$\6
\4\&{else} $\|b\K(\\{type}(\|p)=\\{vlist\_node})$;\2\2\2\6
\&{end}\par
\U section~501.\fi

\M506. An active character will be treated as category 13 following
\.{\\if\\noexpand} or \.{\\ifcat\\noexpand}. We use the fact that
active characters have the smallest tokens, among all control sequences.

\Y\P\D \37$\\{get\_x\_token\_or\_active\_char}\S\hbox{}$\6
\&{begin} \37\\{get\_x\_token};\6
\&{if} $\\{cur\_cmd}=\\{relax}$ \1\&{then}\6
\&{if} $\\{cur\_chr}=\\{no\_expand\_flag}$ \1\&{then}\6
\&{begin} \37$\\{cur\_cmd}\K\\{active\_char}$;\5
$\\{cur\_chr}\K\\{cur\_tok}-\\{cs\_token\_flag}-\\{active\_base}$;\6
\&{end};\2\2\6
\&{end}\par
\Y\P$\4\X506:Test if two characters match\X\S$\6
\&{begin} \37\\{get\_x\_token\_or\_active\_char};\6
\&{if} $(\\{cur\_cmd}>\\{active\_char})\V(\\{cur\_chr}>127)$ \1\&{then}\6
\&{begin} \37$\|m\K\\{relax}$;\5
$\|n\K256$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\|m\K\\{cur\_cmd}$;\5
$\|n\K\\{cur\_chr}$;\6
\&{end};\2\6
\\{get\_x\_token\_or\_active\_char};\6
\&{if} $(\\{cur\_cmd}>\\{active\_char})\V(\\{cur\_chr}>127)$ \1\&{then}\6
\&{begin} \37$\\{cur\_cmd}\K\\{relax}$;\5
$\\{cur\_chr}\K256$;\6
\&{end};\2\6
\&{if} $\\{this\_if}=\\{if\_char\_code}$ \1\&{then}\5
$\|b\K(\|n=\\{cur\_chr})$\ \&{else} $\|b\K(\|m=\\{cur\_cmd})$;\2\6
\&{end}\par
\U section~501.\fi

\M507. Note that `\.{\\ifx}' will declare two macros different if one is %
\\{long}
or \\{outer} and the other isn't, even though the texts of the macros are
the same.

We need to reset \\{scanner\_status}, since \.{\\outer} control sequences
are allowed, but we might be scanning a macro definition or preamble.

\Y\P$\4\X507:Test if two tokens match\X\S$\6
\&{begin} \37$\\{save\_scanner\_status}\K\\{scanner\_status}$;\5
$\\{scanner\_status}\K\\{normal}$;\5
\\{get\_next};\5
$\|n\K\\{cur\_cs}$;\5
$\|p\K\\{cur\_cmd}$;\5
$\|q\K\\{cur\_chr}$;\5
\\{get\_next};\6
\&{if} $\\{cur\_cmd}\I\|p$ \1\&{then}\5
$\|b\K\\{false}$\6
\4\&{else} \&{if} $\\{cur\_cmd}<\\{call}$ \1\&{then}\5
$\|b\K(\\{cur\_chr}=\|q)$\6
\4\&{else} \X508:Test if two macro texts match\X;\2\2\6
$\\{scanner\_status}\K\\{save\_scanner\_status}$;\6
\&{end}\par
\U section~501.\fi

\M508. Note also that `\.{\\ifx}' decides that macros \.{\\a} and \.{\\b} are
different in examples like this:
$$\vbox{\halign{\.{#}\hfil\cr
{}\\def\\a\{\\c\}\cr
{}\\def\\b\{\\d\}\cr
{}\\def\\c\{\}\cr
{}\\def\\d\{\}\cr}}$$

\Y\P$\4\X508:Test if two macro texts match\X\S$\6
\&{begin} \37$\|p\K\\{link}(\\{cur\_chr})$;\5
$\|q\K\\{link}(\\{equiv}(\|n))$;\C{omit reference counts}\6
\&{while} $(\|p\I\\{null})\W(\|q\I\\{null})$ \1\&{do}\6
\&{if} $\\{info}(\|p)\I\\{info}(\|q)$ \1\&{then}\5
$\|p\K\\{null}$\6
\4\&{else} \&{begin} \37$\|p\K\\{link}(\|p)$;\5
$\|q\K\\{link}(\|q)$;\6
\&{end};\2\2\6
$\|b\K((\|p=\\{null})\W(\|q=\\{null}))$;\6
\&{end}\par
\U section~507.\fi

\M509. \P$\X509:Select the appropriate case and \&{return} or \&{goto} %
\\{common\_ending}\X\S$\6
\&{begin} \37\\{scan\_int};\5
$\|n\K\\{cur\_val}$;\C{\|n is the number of cases to pass}\6
\&{if} $\\{tracing\_commands}>1$ \1\&{then}\6
\&{begin} \37\\{begin\_diagnostic};\5
$\\{print}(\.{"\{case\ "})$;\5
$\\{print\_int}(\|n)$;\5
$\\{print\_char}(\.{"\}"})$;\5
$\\{end\_diagnostic}(\\{false})$;\6
\&{end};\2\6
\&{while} $\|n\I0$ \1\&{do}\6
\&{begin} \37\\{pass\_text};\6
\&{if} $\\{cond\_ptr}=\\{save\_cond\_ptr}$ \1\&{then}\6
\&{if} $\\{cur\_chr}=\\{or\_code}$ \1\&{then}\5
$\\{decr}(\|n)$\6
\4\&{else} \&{goto} \37\\{common\_ending}\2\6
\4\&{else} \&{if} $\\{cur\_chr}=\\{fi\_code}$ \1\&{then}\5
\X496:Pop the condition stack\X;\2\2\6
\&{end};\2\6
$\\{change\_if\_limit}(\\{or\_code},\39\\{save\_cond\_ptr})$;\5
\&{return};\C{wait for \.{\\or}, \.{\\else}, or \.{\\fi}}\6
\&{end}\par
\U section~501.\fi

\M510. The processing of conditionals is complete except for the following
code, which is actually part of \\{expand}. It comes into play when
\.{\\or}, \.{\\else}, or \.{\\fi} is scanned.

\Y\P$\4\X510:Terminate the current conditional and skip to \.{\\fi}\X\S$\6
\&{if} $\\{cur\_chr}>\\{if\_limit}$ \1\&{then}\6
\&{if} $\\{if\_limit}=\\{if\_code}$ \1\&{then}\5
\\{insert\_relax}\C{condition not yet evaluated}\6
\4\&{else} \&{begin} \37$\\{print\_err}(\.{"Extra\ "})$;\5
$\\{print\_cmd\_chr}(\\{fi\_or\_else},\39\\{cur\_chr})$;\5
$\\{help1}(\.{"I\'m\ ignoring\ this;\ it\ doesn\'t\ match\ any\ \\if."})$;\5
\\{error};\6
\&{end}\2\6
\4\&{else} \&{begin} \37\&{while} $\\{cur\_chr}\I\\{fi\_code}$ \1\&{do}\5
\\{pass\_text};\C{skip to \.{\\fi}}\2\6
\X496:Pop the condition stack\X;\6
\&{end}\2\par
\U section~367.\fi

\N511.  \[29] File names.
It's time now to fret about file names.  Besides the fact that different
operating systems treat files in different ways, we must cope with the
fact that completely different naming conventions are used by different
groups of people. The following programs show what is required for one
particular operating system; similar routines for other systems are not
difficult to devise.

\TeX\ assumes that a file name has three parts: the name proper; its
``extension''; and a ``file area'' where it is found in an external file
system.  The extension of an input file or a write file is assumed to be
`\.{.tex}' unless otherwise specified; it is `\.{.log}' on the
transcript file that records each run of \TeX; it is `\.{.tfm}' on the font
metric files that describe characters in the fonts \TeX\ uses; it is
`\.{.dvi}' on the output files that specify typesetting information; and it
is `\.{.fmt}' on the format files written by \.{INITEX} to initialize \TeX.
The file area can be arbitrary on input files, but files are usually
output to the user's current area.  If an input file cannot be
found on the specified area, \TeX\ will look for it on a special system
area; this special area is intended for commonly used input files like
\.{webhdr.tex}.

Simple uses of \TeX\ refer only to file names that have no explicit
extension or area. For example, a person usually says `\.{\\input} \.{paper}'
or `\.{\\font\\tenrm} \.= \.{helvetica}' instead of `\.{\\input}
\.{paper.new}' or `\.{\\font\\tenrm} \.= \.{<csd.knuth>test}'. Simple file
names are best, because they make the \TeX\ source files portable;
whenever a file name consists entirely of letters and digits, it should be
treated in the same way by all implementations of \TeX. However, users
need the ability to refer to other files in their environment, especially
when responding to error messages concerning unopenable files; therefore
we want to let them use the syntax that appears in their favorite
operating system.

\fi

\M512. In order to isolate the system-dependent aspects of file names, the
system-independent parts of \TeX\ make use of three system-dependent
procedures that are called \\{begin\_name}, \\{more\_name}, and \\{end\_name}.
In
essence, if the user-specified characters of the file name are $c_1\ldots c_n$,
the system-independent driver program does the operations
$$\\{begin\_name};\,\\{more\_name}(c_1);\,\ldots\,;\\{more\_name}(c_n);
\,\\{end\_name}.$$
These three procedures communicate with each other via global variables.
Afterwards the file name will appear in the string pool as three strings
called \\{cur\_name}\penalty10000\hskip-.05em,
\\{cur\_area}, and \\{cur\_ext}; the latter two are null (i.e.,
\.{""}), unless they were explicitly specified by the user.

Actually the situation is slightly more complicated, because \TeX\ needs
to know when the file name ends. The \\{more\_name} routine is a function
(with side effects) that returns \\{true} on the calls \\{more\_name}$(c_1)$,
\dots, \\{more\_name}$(c_{n-1})$. The final call \\{more\_name}$(c_n)$
returns \\{false}; or, it returns \\{true} and the token following $c_n$ is
something like `\.{\\hbox}' (i.e., not a character). In other words,
\\{more\_name} is supposed to return \\{true} unless it is sure that the
file name has been completely scanned; and \\{end\_name} is supposed to be able
to finish the assembly of \\{cur\_name}, \\{cur\_area}, and \\{cur\_ext}
regardless of
whether $\\{more\_name}(c_n)$ returned \\{true} or \\{false}.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{cur\_name}: \37\\{str\_number};\C{name of file just scanned}\6
\4\\{cur\_area}: \37\\{str\_number};\C{file area just scanned, or \.{""}}\6
\4\\{cur\_ext}: \37\\{str\_number};\C{file extension just scanned, or \.{""}}%
\par
\fi

\M513\*. The file names we shall deal with have the following structure:
If the name contains `\.[', the file area consists of all characters
from this character to the end; otherwise the file area is null.
If the remaining file name contains `\..', the file extension consists of all
such characters from this character to the end, otherwise the file extension
is null. We can assume that there is at most one `\.[' and at most one `\..'.

We can scan such file names easily by using two global variables that keep
track
of the occurrences of area and extension delimiters:

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{area\_delimiter}: \37\\{pool\_pointer};\C{the most recent `\.[', if any}\6
\4\\{ext\_delimiter}: \37\\{pool\_pointer};\C{the relevant `\..', if any}\par
\fi

\M514\*. Input files that can't be found in the user's area may appear in a
standard
system area called \\{TEX\_area}. Font metric files whose areas are not given
explicitly are assumed to appear in a standard system area called
\\{TEX\_font\_area}.  These system area names will, of course, vary from place
to place.

\Y\P\D \37$\\{TEX\_area}\S\.{"[tex,sys]"}$\par
\P\D \37$\\{TEX\_font\_area}\S\.{"[tfm,sys]"}$\par
\fi

\M515. Here now is the first of the system-dependent routines for file name
scanning.

\Y\P\4\&{procedure}\1\  \37\\{begin\_name};\2\6
\&{begin} \37$\\{area\_delimiter}\K0$;\5
$\\{ext\_delimiter}\K0$;\6
\&{end};\par
\fi

\M516\*. And here's the second.

\Y\P\4\&{function}\1\  \37$\\{more\_name}(\|c:\\{ASCII\_code})$: \37%
\\{boolean};\2\6
\&{begin} \37\&{if} $\|c=\.{"\ "}$ \1\&{then}\5
$\\{more\_name}\K\\{false}$\6
\4\&{else} \&{begin} \37\&{if} $\|c=\.{"["}$ \1\&{then}\5
$\\{area\_delimiter}\K\\{pool\_ptr}$\6
\4\&{else} \&{if} $\|c=\.{"."}$ \1\&{then}\5
$\\{ext\_delimiter}\K\\{pool\_ptr}$;\2\2\6
$\\{str\_room}(1)$;\5
$\\{append\_char}(\|c)$;\C{contribute \|c to the current string}\6
$\\{more\_name}\K\\{true}$;\6
\&{end};\2\6
\&{end};\par
\fi

\M517\*. The third.

\Y\P\4\&{procedure}\1\  \37\\{end\_name};\2\6
\&{begin} \37\&{if} $\\{str\_ptr}+3>\\{max\_strings}$ \1\&{then}\5
$\\{overflow}(\.{"number\ of\ strings"},\39\\{max\_strings}-\\{init\_str%
\_ptr})$;\2\6
$\\{cur\_name}\K\\{str\_ptr}$;\6
\&{if} $\\{ext\_delimiter}=0$ \1\&{then}\5
$\\{cur\_ext}\K\.{""}$\6
\4\&{else} \&{begin} \37$\\{incr}(\\{str\_ptr})$;\5
$\\{str\_start}[\\{str\_ptr}]\K\\{ext\_delimiter}$;\5
$\\{cur\_ext}\K\\{str\_ptr}$;\6
\&{end};\2\6
\&{if} $\\{area\_delimiter}\L\\{str\_start}[\\{str\_ptr}]$ \1\&{then}\6
\&{begin} \37$\\{cur\_area}\K\.{""}$;\5
$\\{incr}(\\{str\_ptr})$;\5
$\\{str\_start}[\\{str\_ptr}]\K\\{pool\_ptr}$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{incr}(\\{str\_ptr})$;\5
$\\{str\_start}[\\{str\_ptr}]\K\\{area\_delimiter}$;\5
$\\{cur\_area}\K\\{make\_string}$;\6
\&{end};\2\6
\&{end};\par
\fi

\M518\*. Conversely, here is a routine that takes three strings and prints a
file
name that might have produced them. (The routine is system dependent, because
some operating systems put the file area last instead of first.)

\Y\P$\4\X57:Basic printing procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{print\_file\_name}(\|n,\39\|a,\39\|e:\\{integer})$;%
\2\6
\&{begin} \37$\\{print}(\|n)$;\5
$\\{print}(\|e)$;\5
$\\{print}(\|a)$;\6
\&{end};\par
\fi

\M519\*. Another system-dependent routine is needed to convert three \TeX\
strings
into the \\{name\_of\_file} value that is used to open files. The present code
allows both lowercase and uppercase letters in the file name.

\Y\P\D \37$\\{append\_to\_name}(\#)\S$\1\6
\&{begin} \37$\|c\K\#$;\5
$\\{incr}(\|k)$;\6
\&{if} $\|k\L\\{file\_name\_size}$ \1\&{then}\5
$\\{name\_of\_file}[\|k]\K\\{xchr}[\|c]$;\2\6
\&{end}\2\par
\Y\P\4\&{procedure}\1\  \37$\\{pack\_file\_name}(\|n,\39\|a,\39\|e:\\{str%
\_number})$;\6
\4\&{var} \37\|k: \37\\{integer};\C{number of positions filled in \\{name\_of%
\_file}}\6
\|c: \37\\{ASCII\_code};\C{character being packed}\6
\|j: \37\\{pool\_pointer};\C{index into \\{str\_pool}}\2\6
\&{begin} \37$\|k\K0$;\5
$\|j\K\.{".tfm"}$;\C{this keeps \.{tex.pool} the same as in production \TeX}\6
\&{for} $\|j\K\\{str\_start}[\|n]\mathrel{\&{to}}\\{str\_start}[\|n+1]-1$ \1%
\&{do}\5
$\\{append\_to\_name}(\\{str\_pool}[\|j])$;\2\6
\&{for} $\|j\K\\{str\_start}[\|e]\mathrel{\&{to}}\\{str\_start}[\|e+1]-1$ \1%
\&{do}\5
$\\{append\_to\_name}(\\{str\_pool}[\|j])$;\2\6
\&{for} $\|j\K\\{str\_start}[\|a]\mathrel{\&{to}}\\{str\_start}[\|a+1]-1$ \1%
\&{do}\5
$\\{append\_to\_name}(\\{str\_pool}[\|j])$;\2\6
\&{if} $\|k\L\\{file\_name\_size}$ \1\&{then}\5
$\\{name\_length}\K\|k$\ \&{else} $\\{name\_length}\K\\{file\_name\_size}$;\2\6
\&{for} $\|k\K\\{name\_length}+1\mathrel{\&{to}}\\{file\_name\_size}$ \1\&{do}\5
$\\{name\_of\_file}[\|k]\K\.{\'\ \'}$;\2\6
\&{end};\par
\fi

\M520\*. A messier routine is also needed, since format file names must be
scanned
before \TeX's string mechanism has been initialized. We shall use the
global variable \\{TEX\_format\_default} to supply the text for default system
areas
and extensions related to format files.

\Y\P\D \37$\\{format\_default\_length}=18$\C{length of the \\{TEX\_format%
\_default} string}\par
\P\D \37$\\{format\_area\_length}=9$\C{length of its area part}\par
\P\D \37$\\{format\_ext\_length}=4$\C{length of its `\.{.fmt}' part}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{TEX\_format\_default}: \37\&{packed} \37\&{array} $[1\to\\{format\_default%
\_length}]$ \1\&{of}\5
\\{char};\2\par
\fi

\M521\*. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{TEX\_format\_default}\K\.{\'plain.fmt[tex,sys]\'}$;\par
\fi

\M522. \P$\X14:Check the ``constant'' values for consistency\X\mathrel{+}\S$\6
\&{if} $\\{format\_default\_length}>\\{file\_name\_size}$ \1\&{then}\5
$\\{bad}\K31$;\2\par
\fi

\M523\*. Here is the messy routine that was just mentioned. It sets \\{name\_of%
\_file}
from the first \|n characters of \\{TEX\_format\_default}, followed by
$\\{buffer}[\|a\to\|b]$, followed by the last \\{format\_ext\_length}
characters of
\\{TEX\_format\_default}; but it actually switches stuff around to keep the
file area last.

We dare not give error messages here, since \TeX\ calls this routine before
the \\{error} routine is ready to roll. Instead, we simply drop excess
characters,
since the error will be detected in another way when a strange file name
isn't found.

\Y\P\4\&{procedure}\1\  \37$\\{pack\_buffered\_name}(\|n:\\{small\_number};\,%
\35\|a,\39\|b:\\{integer})$;\6
\4\&{var} \37\|k: \37\\{integer};\C{number of positions filled in \\{name\_of%
\_file}}\6
\|c: \37\\{ASCII\_code};\C{character being packed}\6
\|j: \37\\{integer};\C{index into \\{buffer} or \\{TEX\_format\_default}}\6
\|d: \37\\{integer};\C{a kludge}\2\6
\&{begin} \37\&{if} $\|n+\|b-\|a+1+\\{format\_ext\_length}>\\{file\_name%
\_size}$ \1\&{then}\5
$\|b\K\|a+\\{file\_name\_size}-\|n-1-\\{format\_ext\_length}$;\2\6
$\|k\K0$;\6
\&{for} $\|j\K\|a\mathrel{\&{to}}\|b$ \1\&{do}\5
$\\{append\_to\_name}(\\{buffer}[\|j])$;\2\6
\&{if} $\|b=0$ \1\&{then}\6
\&{begin} \37$\|d\K\\{format\_default\_length}-\\{format\_area\_length}+1$;\5
$\|n\K\\{format\_default\_length}$;\6
\&{end}\6
\4\&{else} $\|d\K\\{format\_default\_length}-\\{format\_area\_length}-\\{format%
\_ext\_length}+1$;\2\6
\&{for} $\|j\K\|d\mathrel{\&{to}}\\{format\_default\_length}-\\{format\_area%
\_length}$ \1\&{do}\5
$\\{append\_to\_name}(\\{xord}[\\{TEX\_format\_default}[\|j]])$;\2\6
\&{for} $\|j\K\\{format\_default\_length}-\|n+1\mathrel{\&{to}}\\{format%
\_default\_length}$ \1\&{do}\5
$\\{append\_to\_name}(\\{xord}[\\{TEX\_format\_default}[\|j]])$;\2\6
\&{if} $\|k\L\\{file\_name\_size}$ \1\&{then}\5
$\\{name\_length}\K\|k$\ \&{else} $\\{name\_length}\K\\{file\_name\_size}$;\2\6
\&{for} $\|k\K\\{name\_length}+1\mathrel{\&{to}}\\{file\_name\_size}$ \1\&{do}\5
$\\{name\_of\_file}[\|k]\K\.{\'\ \'}$;\2\6
\&{end};\par
\fi

\M524. Here is the only place we use \\{pack\_buffered\_name}. This part of the
program
becomes active when a ``virgin'' \TeX\ is trying to get going, just after
the preliminary initialization, or when the user is substituting another
format file by typing `\.\&' after the initial `\.{**}' prompt.  The buffer
contains the first line of input in $\\{buffer}[\\{loc}\to(\\{last}-1)]$, where
$\\{loc}<\\{last}$ and $\\{buffer}[\\{loc}]\I\.{"\ "}$.

\Y\P$\4\X524:Declare the function called \\{open\_fmt\_file}\X\S$\6
\4\&{function}\1\  \37\\{open\_fmt\_file}: \37\\{boolean};\6
\4\&{label} \37$\\{found},\39\\{exit}$;\6
\4\&{var} \37\|j: \37$0\to\\{buf\_size}$;\C{the first space after the format
file name}\2\6
\&{begin} \37$\|j\K\\{loc}$;\6
\&{if} $\\{buffer}[\\{loc}]=\.{"\&"}$ \1\&{then}\6
\&{begin} \37$\\{incr}(\\{loc})$;\5
$\|j\K\\{loc}$;\5
$\\{buffer}[\\{last}]\K\.{"\ "}$;\6
\&{while} $\\{buffer}[\|j]\I\.{"\ "}$ \1\&{do}\5
$\\{incr}(\|j)$;\2\6
$\\{pack\_buffered\_name}(0,\39\\{loc},\39\|j-1)$;\C{try first without the
system file area}\6
\&{if} $\\{w\_open\_in}(\\{fmt\_file})$ \1\&{then}\5
\&{goto} \37\\{found};\2\6
$\\{pack\_buffered\_name}(\\{format\_area\_length},\39\\{loc},\39\|j-1)$;\C{now
try the system format file area}\6
\&{if} $\\{w\_open\_in}(\\{fmt\_file})$ \1\&{then}\5
\&{goto} \37\\{found};\2\6
\\{wake\_up\_terminal};\5
$\\{wterm\_ln}(\.{\'Sorry,\ I\ can\'}\.{\'t\ find\ that\ format;\'},\39\.{\'\
will\ try\ PLAIN.\'})$;\5
\\{update\_terminal};\6
\&{end};\C{now pull out all the stops: try for the system \.{plain} file}\2\6
$\\{pack\_buffered\_name}(\\{format\_default\_length}-\\{format\_ext\_length},%
\391,\390)$;\6
\&{if} $\R\\{w\_open\_in}(\\{fmt\_file})$ \1\&{then}\6
\&{begin} \37\\{wake\_up\_terminal};\5
$\\{wterm\_ln}(\.{\'I\ can\'}\.{\'t\ find\ the\ PLAIN\ format\ file!\'})$;\5
$\\{open\_fmt\_file}\K\\{false}$;\5
\&{return};\6
\&{end};\2\6
\4\\{found}: \37$\\{loc}\K\|j$;\5
$\\{open\_fmt\_file}\K\\{true}$;\6
\4\\{exit}: \37\&{end};\par
\U section~1303.\fi

\M525\*. Operating systems often make it possible to determine the exact name
(and
possible version number) of a file that has been opened. The following routine,
which simply makes a \TeX\ string from the value of \\{name\_of\_file}, should
ideally be changed to deduce the full name of file~\|f, which is the file
most recently opened, if it is possible to do this in a \PASCAL\ program.

This routine might be called after string memory has overflowed, hence
we dare not use `\\{str\_room}'.

\Y\P\4\&{function}\1\  \37\\{make\_name\_string}: \37\\{str\_number};\6
\4\&{var} \37\|k: \37$1\to\\{file\_name\_size}$;\C{index into \\{name\_of%
\_file}}\2\6
\&{begin} \37\&{if} $(\\{pool\_ptr}+\\{name\_length}>\\{pool\_size})\V(\\{str%
\_ptr}=\\{max\_strings})$ \1\&{then}\5
$\\{make\_name\_string}\K\.{"?"}$\6
\4\&{else} \&{begin} \37\&{for} $\|k\K1\mathrel{\&{to}}\\{name\_length}$ \1%
\&{do}\5
$\\{append\_char}(\\{xord}[\\{name\_of\_file}[\|k]])$;\2\6
$\\{make\_name\_string}\K\\{make\_string}$;\6
\&{end};\2\6
\&{end};\6
\4\&{function}\1\  \37$\\{a\_make\_name\_string}(\mathop{\&{var}}\|f:\\{alpha%
\_file})$: \37\\{str\_number};\2\6
\&{begin} \37$\\{a\_make\_name\_string}\K\\{make\_name\_string}$;\6
\&{end};\6
\4\&{function}\1\  \37$\\{b\_make\_name\_string}(\mathop{\&{var}}\|f:\\{byte%
\_file})$: \37\\{str\_number};\2\6
\&{begin} \37$\\{b\_make\_name\_string}\K\\{make\_name\_string}$;\6
\&{end};\6
\4\&{function}\1\  \37$\\{w\_make\_name\_string}(\mathop{\&{var}}\|f:\\{word%
\_file})$: \37\\{str\_number};\2\6
\&{begin} \37$\\{w\_make\_name\_string}\K\\{make\_name\_string}$;\6
\&{end};\par
\fi

\M526. Now let's consider the routines by which \TeX\ deals with file names
in a system-independent manner.  First comes a procedure that looks for a
file name in the input by calling \\{get\_x\_token} for the information.

\Y\P\4\&{procedure}\1\  \37\\{scan\_file\_name};\6
\4\&{label} \37\\{done};\2\6
\&{begin} \37$\\{name\_in\_progress}\K\\{true}$;\5
\\{begin\_name};\5
\X406:Get the next non-blank non-call token\X;\6
\~ \1\&{loop}\ \&{begin} \37\&{if} $(\\{cur\_cmd}>\\{other\_char})\V(\\{cur%
\_chr}>127)$ \1\&{then}\C{not a character}\6
\&{begin} \37\\{back\_input};\5
\&{goto} \37\\{done};\6
\&{end};\2\6
\&{if} $\R\\{more\_name}(\\{cur\_chr})$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
\\{get\_x\_token};\6
\&{end};\2\6
\4\\{done}: \37\\{end\_name};\5
$\\{name\_in\_progress}\K\\{false}$;\6
\&{end};\par
\fi

\M527. The global variable \\{name\_in\_progress} is used to prevent recursive
use of \\{scan\_file\_name}, since the \\{begin\_name} and other procedures
communicate via global variables. Recursion would arise only by
devious tricks like `\.{\\input\\input f}'; such attempts at sabotage
must be thwarted. Furthermore, \\{name\_in\_progress} prevents \.{\\input}
from being initiated when a font size specification is being scanned.

Another global variable, \\{job\_name}, contains the file name that was first
\.{\\input} by the user. This name is extended by `\.{log}' and `\.{dvi}'
and `\.{fmt}' in order to make the names of \TeX's output files.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{name\_in\_progress}: \37\\{boolean};\C{is a file name being scanned?}\6
\4\\{job\_name}: \37\\{str\_number};\C{principal file name}\par
\fi

\M528. Initially $\\{job\_name}=0$; it becomes nonzero as soon as the true name
is known.
We have $\\{job\_name}=0$ if and only if the `\.{log}' file has not been
opened,
except of course for a short time just after \\{job\_name} has become nonzero.

\Y\P$\4\X55:Initialize the output routines\X\mathrel{+}\S$\6
$\\{job\_name}\K0$;\5
$\\{name\_in\_progress}\K\\{false}$;\par
\fi

\M529. Here is a routine that manufactures the output file names, assuming that
$\\{job\_name}\I0$. It ignores and changes the current settings of \\{cur%
\_area}
and \\{cur\_ext}.

\Y\P\D \37$\\{pack\_cur\_name}\S\\{pack\_file\_name}(\\{cur\_name},\39\\{cur%
\_area},\39\\{cur\_ext})$\par
\Y\P\4\&{procedure}\1\  \37$\\{pack\_job\_name}(\|s:\\{str\_number})$;\C{$\|s=%
\.{".log"}$, \.{".dvi"}, or 	\.{".fmt"}}\2\6
\&{begin} \37$\\{cur\_area}\K\.{""}$;\5
$\\{cur\_ext}\K\|s$;\5
$\\{cur\_name}\K\\{job\_name}$;\5
\\{pack\_cur\_name};\6
\&{end};\par
\fi

\M530\*. If some trouble arises when \TeX\ tries to open a file, the following
routine calls upon the user to supply another file name. Parameter~\|s
is used in the error message to identify the type of file; parameter~\|e
is the default extension if none is given. Upon exit from the routine,
variables \\{cur\_name}, \\{cur\_area}, \\{cur\_ext}, and \\{name\_of\_file}
are
ready for another attempt at file opening.

\Y\P\4\&{procedure}\1\  \37$\\{prompt\_file\_name}(\|s,\39\|e:\\{str%
\_number})$;\6
\4\&{label} \37\\{done};\6
\4\&{var} \37\|k: \37$0\to\\{buf\_size}$;\C{index into \\{buffer}}\6
\|i: \37\\{pool\_pointer};\C{index into \\{str\_pool}}\2\6
\&{begin} \37\&{if} $\\{interaction}=\\{scroll\_mode}$ \1\&{then}\5
\\{wake\_up\_terminal};\2\6
\&{if} $\|s=\.{"input\ file\ name"}$ \1\&{then}\5
$\\{print\_err}(\.{"I\ can\'t\ find\ file\ \`"})$\6
\4\&{else} $\\{print\_err}(\.{"I\ can\'t\ write\ on\ file\ \`"})$;\2\6
$\\{print\_file\_name}(\\{cur\_name},\39\\{cur\_area},\39\\{cur\_ext})$;\5
$\\{print}(\.{"\'."})$;\6
\&{if} $\|e=\.{".tex"}$ \1\&{then}\5
\\{show\_context};\2\6
$\\{print\_nl}(\.{"Please\ type\ another\ "})$;\5
$\\{print}(\|s)$;\6
\&{if} $\\{interaction}<\\{scroll\_mode}$ \1\&{then}\5
$\\{fatal\_error}(\.{"***\ (job\ aborted,\ file\ error\ in\ nonstop\ mode)"})$;%
\2\6
\\{clear\_terminal};\C{now we'll fill the line editor's buffer with the old
name}\6
\&{for} $\|i\K\\{str\_start}[\\{cur\_name}]\mathrel{\&{to}}\\{str\_start}[%
\\{cur\_name}+1]-1$ \1\&{do}\5
$\\{pto\_chr}(\\{xchr}[\\{str\_pool}[\|i]])$;\2\6
\&{for} $\|i\K\\{str\_start}[\\{cur\_ext}]\mathrel{\&{to}}\\{str\_start}[\\{cur%
\_ext}+1]-1$ \1\&{do}\5
$\\{pto\_chr}(\\{xchr}[\\{str\_pool}[\|i]])$;\2\6
\&{for} $\|i\K\\{str\_start}[\\{cur\_area}]\mathrel{\&{to}}\\{str\_start}[%
\\{cur\_area}+1]-1$ \1\&{do}\5
$\\{pto\_chr}(\\{xchr}[\\{str\_pool}[\|i]])$;\2\6
$\\{ptwr1w}(0,\39\O{214})$;\C{control-formfeed returns cursor to start of line}%
\6
$\\{prompt\_input}(\.{":\ "})$;\5
\X531:Scan file name in the buffer\X;\6
\&{if} $\\{cur\_ext}=\.{""}$ \1\&{then}\5
$\\{cur\_ext}\K\|e$;\2\6
\\{pack\_cur\_name};\6
\&{end};\par
\fi

\M531. \P$\X531:Scan file name in the buffer\X\S$\6
\&{begin} \37\\{begin\_name};\5
$\|k\K\\{first}$;\6
\&{while} $(\\{buffer}[\|k]=\.{"\ "})\W(\|k<\\{last})$ \1\&{do}\5
$\\{incr}(\|k)$;\2\6
\~ \1\&{loop}\ \&{begin} \37\&{if} $\|k=\\{last}$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
\&{if} $\R\\{more\_name}(\\{buffer}[\|k])$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
$\\{incr}(\|k)$;\6
\&{end};\2\6
\4\\{done}: \37\\{end\_name};\6
\&{end}\par
\U section~530\*.\fi

\M532. Here's an example of how these conventions are used. We shall use the
macro \\{ensure\_dvi\_open} when it is time to ship out a box of stuff.

\Y\P\D \37$\\{ensure\_dvi\_open}\S$\1\6
\&{if} $\\{output\_file\_name}=0$ \1\&{then}\6
\&{begin} \37\&{if} $\\{job\_name}=0$ \1\&{then}\5
\\{open\_log\_file};\2\6
$\\{pack\_job\_name}(\.{".dvi"})$;\6
\&{while} $\R\\{b\_open\_out}(\\{dvi\_file})$ \1\&{do}\5
$\\{prompt\_file\_name}(\.{"file\ name\ for\ output"},\39\.{".dvi"})$;\2\6
$\\{output\_file\_name}\K\\{b\_make\_name\_string}(\\{dvi\_file})$;\6
\&{end}\2\2\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{dvi\_file}: \37\\{byte\_file};\C{the device-independent output goes here}\6
\4\\{output\_file\_name}: \37\\{str\_number};\C{full name of the output file}\6
\4\\{log\_name}: \37\\{str\_number};\C{full name of the log file}\par
\fi

\M533. \P$\X55:Initialize the output routines\X\mathrel{+}\S$\6
$\\{output\_file\_name}\K0$;\par
\fi

\M534. The \\{open\_log\_file} routine is used to open the transcript file and
to help
it catch up to what has previously been printed on the terminal.

\Y\P\4\&{procedure}\1\  \37\\{open\_log\_file};\6
\4\&{var} \37\\{old\_setting}: \37$0\to\\{max\_selector}$;\C{previous %
\\{selector} setting}\6
\|k: \37$0\to\\{buf\_size}$;\C{index into \\{months} and \\{buffer}}\6
\|l: \37$0\to\\{buf\_size}$;\C{end of first input line}\6
\\{months}: \37\&{packed} \37\&{array} $[1\to36]$ \1\&{of}\5
\\{char};\C{abbreviations of month names}\2\2\6
\&{begin} \37$\\{old\_setting}\K\\{selector}$;\6
\&{if} $\\{job\_name}=0$ \1\&{then}\5
$\\{job\_name}\K\.{"texput"}$;\2\6
$\\{pack\_job\_name}(\.{".log"})$;\6
\&{while} $\R\\{a\_open\_out}(\\{log\_file})$ \1\&{do}\5
\X535:Try to get a different log file name\X;\2\6
$\\{log\_name}\K\\{a\_make\_name\_string}(\\{log\_file})$;\5
$\\{selector}\K\\{log\_only}$;\5
\X536:Print the banner line, including the date and time\X;\6
$\\{input\_stack}[\\{input\_ptr}]\K\\{cur\_input}$;\C{make sure bottom level is
in memory}\6
$\\{print\_nl}(\.{"**"})$;\5
$\|l\K\\{input\_stack}[0].\\{limit\_field}$;\C{last position of first line}\6
\&{if} $\\{buffer}[\|l]=\\{end\_line\_char}$ \1\&{then}\5
$\\{decr}(\|l)$;\2\6
\&{for} $\|k\K1\mathrel{\&{to}}\|l$ \1\&{do}\5
$\\{print}(\\{buffer}[\|k])$;\2\6
\\{print\_ln};\C{now the transcript file contains the first line of input}\6
$\\{selector}\K\\{old\_setting}+2$;\C{\\{log\_only} or \\{term\_and\_log}}\6
\&{end};\par
\fi

\M535. Sometimes \\{open\_log\_file} is called at awkward moments when \TeX\ is
unable to print error messages or even to \\{show\_context}.
Therefore the program is careful not to call \\{prompt\_file\_name} if a
fatal error could result.

Incidentally, the program always refers to the log file as a `\.{transcript
file}', because some systems cannot use the extension `\.{.log}' for
this file.

\Y\P$\4\X535:Try to get a different log file name\X\S$\6
\&{begin} \37\&{if} $\\{interaction}<\\{scroll\_mode}$ \1\&{then}\C{bypass %
\\{fatal\_error}}\6
\&{begin} \37$\\{print\_err}(\.{"I\ can\'t\ write\ on\ file\ \`"})$;\5
$\\{print\_file\_name}(\\{cur\_name},\39\\{cur\_area},\39\\{cur\_ext})$;\5
$\\{print}(\.{"\'."})$;\6
$\\{job\_name}\K0$;\5
$\\{history}\K\\{fatal\_error\_stop}$;\5
\\{jump\_out};\6
\&{end};\C{abort the program without a log file}\2\6
$\\{prompt\_file\_name}(\.{"transcript\ file\ name"},\39\.{".log"})$;\6
\&{end}\par
\U section~534.\fi

\M536. \P$\X536:Print the banner line, including the date and time\X\S$\6
\&{begin} \37$\\{wlog}(\\{banner})$;\5
$\\{print}(\\{format\_ident})$;\5
$\\{print}(\.{"\ \ "})$;\5
$\\{print\_int}(\\{day})$;\5
$\\{print\_char}(\.{"\ "})$;\5
$\\{months}\K\.{\'JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC\'}$;\6
\&{for} $\|k\K3\ast\\{month}-2\mathrel{\&{to}}3\ast\\{month}$ \1\&{do}\5
$\\{wlog}(\\{months}[\|k])$;\2\6
$\\{print\_char}(\.{"\ "})$;\5
$\\{print\_int}(\\{year})$;\5
$\\{print\_char}(\.{"\ "})$;\5
$\\{print\_two}(\\{time}\mathbin{\&{div}}60)$;\5
$\\{print\_char}(\.{":"})$;\5
$\\{print\_two}(\\{time}\mathbin{\&{mod}}60)$;\6
\&{end}\par
\U section~534.\fi

\M537. Let's turn now to the procedure that is used to initiate file reading
when an `\.{\\input}' command is being processed.

\Y\P\4\&{procedure}\1\  \37\\{start\_input};\C{\TeX\ will \.{\\input}
something}\6
\4\&{label} \37\\{done};\2\6
\&{begin} \37\\{scan\_file\_name};\C{set \\{cur\_name} to desired file name}\6
\&{if} $\\{cur\_ext}=\.{""}$ \1\&{then}\5
$\\{cur\_ext}\K\.{".tex"}$;\2\6
\\{pack\_cur\_name};\6
\~ \1\&{loop}\ \&{begin} \37\\{begin\_file\_reading};\C{set up \\{cur\_file}
and new level of input}\6
\&{if} $\\{a\_open\_in}(\\{cur\_file})$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
\&{if} $\\{cur\_area}=\.{""}$ \1\&{then}\6
\&{begin} \37$\\{pack\_file\_name}(\\{cur\_name},\39\\{TEX\_area},\39\\{cur%
\_ext})$;\6
\&{if} $\\{a\_open\_in}(\\{cur\_file})$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
\&{end};\2\6
\\{end\_file\_reading};\C{remove the level that didn't work}\6
$\\{prompt\_file\_name}(\.{"input\ file\ name"},\39\.{".tex"})$;\6
\&{end};\2\6
\4\\{done}: \37$\\{name}\K\\{a\_make\_name\_string}(\\{cur\_file})$;\6
\&{if} $\\{job\_name}=0$ \1\&{then}\6
\&{begin} \37$\\{job\_name}\K\\{cur\_name}$;\5
\\{open\_log\_file};\6
\&{end};\C{\\{open\_log\_file} doesn't \\{show\_context}, so \\{limit} 		and %
\\{loc} needn't be set to meaningful values yet}\2\6
\&{if} $\\{term\_offset}+\\{length}(\\{name})>\\{max\_print\_line}-2$ \1%
\&{then}\5
\\{print\_ln}\6
\4\&{else} \&{if} $(\\{term\_offset}>0)\V(\\{file\_offset}>0)$ \1\&{then}\5
$\\{print\_char}(\.{"\ "})$;\2\2\6
$\\{print\_char}(\.{"("})$;\5
$\\{print}(\\{name})$;\5
\\{update\_terminal};\5
$\\{state}\K\\{new\_line}$;\6
\&{if} $\\{name}=\\{str\_ptr}-1$ \1\&{then}\C{we can conserve string pool space
now}\6
\&{begin} \37\\{flush\_string};\5
$\\{name}\K\\{cur\_name}$;\6
\&{end};\2\6
\X538\*:Read the first line of the new file\X;\6
\&{end};\par
\fi

\M538\*. Here we have to remember to tell \\{input\_ln} not to do the first %
\\{get},
and we also want to skip over a file directory page. An empty file
is considered to contain a single blank line.

\Y\P$\4\X538\*:Read the first line of the new file\X\S$\6
\&{begin} \37\&{if} $\\{input\_ln}(\\{cur\_file},\39\\{false})$ \1\&{then}\6
\&{begin} \37\&{if} $(\\{last}-\\{start}=29)\W(\\{buffer}[\\{start}]=\.{"C"})%
\W(\\{buffer}[\\{start}+8]=\O{26})$ \1\&{then}\6
\&{begin} \37\&{while} $(\\{cur\_file}\↑\I\\{chr}(\\{form\_feed}))\W(\R\\{eof}(%
\\{cur\_file}))$ \1\&{do}\6
\&{begin} \37$\\{read\_ln}(\\{cur\_file})$;\5
$\\{read}(\\{cur\_file},\39\\{aux\_buf}:\\{temp\_ptr})$;\6
\&{end};\C{skip the directory}\2\6
$\\{buffer}[\\{start}]\K\\{form\_feed}$;\5
$\\{last}\K\\{start}+1$;\6
\&{end};\2\6
\&{end};\2\6
$\\{page}\K1$;\5
\\{firm\_up\_the\_line};\6
\&{if} $(\\{end\_line\_char}<0)\V(\\{end\_line\_char}>127)$ \1\&{then}\5
$\\{decr}(\\{limit})$\6
\4\&{else} $\\{buffer}[\\{limit}]\K\\{end\_line\_char}$;\2\6
$\\{first}\K\\{limit}+1$;\5
$\\{loc}\K\\{start}$;\5
$\\{line}\K1$;\6
\&{end}\par
\U section~537.\fi

\N539.  \[30] Font metric data.
\TeX\ gets its knowledge about fonts from font metric files, also called
\.{TFM} files; the `\.T' in `\.{TFM}' stands for \TeX,
but other programs know about them too.

The information in a \.{TFM} file appears in a sequence of 8-bit bytes.
Since the number of bytes is always a multiple of 4, we could
also regard the file as a sequence of 32-bit words, but \TeX\ uses the
byte interpretation. The format of \.{TFM} files was designed by
Lyle Ramshaw in 1980. The intent is to convey a lot of different kinds
of information in a compact but useful form.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{tfm\_file}: \37\\{byte\_file};\par
\fi

\M540. The first 24 bytes (6 words) of a \.{TFM} file contain twelve 16-bit
integers that give the lengths of the various subsequent portions
of the file. These twelve integers are, in order:
$$\vbox{\halign{\hfil#&$\null=\null$#\hfil\cr
\\{lf}&length of the entire file, in words;\cr
\\{lh}&length of the header data, in words;\cr
\\{bc}&smallest character code in the font;\cr
\\{ec}&largest character code in the font;\cr
\\{nw}&number of words in the width table;\cr
\\{nh}&number of words in the height table;\cr
\\{nd}&number of words in the depth table;\cr
\\{ni}&number of words in the italic correction table;\cr
\\{nl}&number of words in the lig/kern table;\cr
\\{nk}&number of words in the kern table;\cr
\\{ne}&number of words in the extensible character table;\cr
\\{np}&number of font parameter words.\cr}}$$
They are all nonnegative and less than $2↑{15}$. We must have $\\{bc}-1\L\\{ec}%
\L255$,
and
$$\hbox{$\\{lf}=6+\\{lh}+(\\{ec}-\\{bc}+1)+\\{nw}+\\{nh}+\\{nd}+\\{ni}+\\{nl}+%
\\{nk}+\\{ne}+\\{np}$.}$$
Note that a font may contain as many as 256 characters (if $\\{bc}=0$ and $%
\\{ec}=255$),
and as few as 0 characters (if $\\{bc}=\\{ec}+1$).

Incidentally, when two or more 8-bit bytes are combined to form an integer of
16 or more bits, the most significant bytes appear first in the file.
This is called BigEndian order.

\fi

\M541. The rest of the \.{TFM} file may be regarded as a sequence of ten data
arrays having the informal specification
$$\def\arr$[#1]#2${\&{array} $[#1]$ \&{of} #2}
\vbox{\halign{\hfil\\{#}&$\,:\,$\arr#\hfil\cr
header&$[0\to\\{lh}-1]\hbox{\\{stuff}}$\cr
char\_info&$[\\{bc}\to\\{ec}]\\{char\_info\_word}$\cr
width&$[0\to\\{nw}-1]\\{fix\_word}$\cr
height&$[0\to\\{nh}-1]\\{fix\_word}$\cr
depth&$[0\to\\{nd}-1]\\{fix\_word}$\cr
italic&$[0\to\\{ni}-1]\\{fix\_word}$\cr
lig\_kern&$[0\to\\{nl}-1]\\{lig\_kern\_command}$\cr
kern&$[0\to\\{nk}-1]\\{fix\_word}$\cr
exten&$[0\to\\{ne}-1]\\{extensible\_recipe}$\cr
param&$[1\to\\{np}]\\{fix\_word}$\cr}}$$
The most important data type used here is a \\{fix\_word}, which is
a 32-bit representation of a binary fraction. A \\{fix\_word} is a signed
quantity, with the two's complement of the entire word used to represent
negation. Of the 32 bits in a \\{fix\_word}, exactly 12 are to the left of the
binary point; thus, the largest \\{fix\_word} value is $2048-2↑{-20}$, and
the smallest is $-2048$. We will see below, however, that all but two of
the \\{fix\_word} values must lie between $-16$ and $+16$.

\fi

\M542. The first data array is a block of header information, which contains
general facts about the font. The header must contain at least two words,
$\\{header}[0]$ and $\\{header}[1]$, whose meaning is explained below.
Additional header information of use to other software routines might
also be included, but \TeX82 does not need to know about such details.
For example, 16 more words of header information are in use at the Xerox
Palo Alto Research Center; the first ten specify the character coding
scheme used (e.g., `\.{XEROX text}' or `\.{TeX math symbols}'), the next five
give the font identifier (e.g., `\.{HELVETICA}' or `\.{CMSY}'), and the
last gives the ``face byte.'' The program that converts \.{DVI} files
to Xerox printing format gets this information by looking at the \.{TFM}
file, which it needs to read anyway because of other information that
is not explicitly repeated in \.{DVI} format.

\yskip\hang$\\{header}[0]$ is a 32-bit check sum that \TeX\ will copy into
the \.{DVI} output file. Later on when the \.{DVI} file is printed,
possibly on another computer, the actual font that gets used is supposed
to have a check sum that agrees with the one in the \.{TFM} file used by
\TeX. In this way, users will be warned about potential incompatibilities.
(However, if the check sum is zero in either the font file or the \.{TFM}
file, no check is made.)  The actual relation between this check sum and
the rest of the \.{TFM} file is not important; the check sum is simply an
identification number with the property that incompatible fonts almost
always have distinct check sums.

\yskip\hang$\\{header}[1]$ is a \\{fix\_word} containing the design size of
the font, in units of \TeX\ points. This number must be at least 1.0; it is
fairly arbitrary, but usually the design size is 10.0 for a ``10 point''
font, i.e., a font that was designed to look best at a 10-point size,
whatever that really means. When a \TeX\ user asks for a font
`\.{at} $\delta$ \.{pt}', the effect is to override the design size
and replace it by $\delta$, and to multiply the $x$ and~$y$ coordinates
of the points in the font image by a factor of $\delta$ divided by the
design size.  {\sl All other dimensions in the\/ \.{TFM} file are
\\{fix\_word}\kern-1pt\ numbers in design-size units}, with the exception of
$\\{param}[1]$ (which denotes the slant ratio). Thus, for example, the value
of $\\{param}[6]$, which defines the \.{em} unit, is often the \\{fix\_word}
value
$2↑{20}=1.0$, since many fonts have a design size equal to one em.
The other dimensions must be less than 16 design-size units in absolute
value; thus, $\\{header}[1]$ and $\\{param}[1]$ are the only \\{fix\_word}
entries in the whole \.{TFM} file whose first byte might be something
besides 0 or 255.

\fi

\M543. Next comes the \\{char\_info} array, which contains one \\{char\_info%
\_word}
per character. Each word in this part of the file contains six fields
packed into four bytes as follows.

\yskip\hang first byte: \\{width\_index} (8 bits)\par
\hang second byte: \\{height\_index} (4 bits) times 16, plus \\{depth\_index}
(4~bits)\par
\hang third byte: \\{italic\_index} (6 bits) times 4, plus \\{tag}
(2~bits)\par
\hang fourth byte: \\{remainder} (8 bits)\par
\yskip\noindent
The actual width of a character is \\{width}$[\\{width\_index}]$, in
design-size
units; this is a device for compressing information, since many characters
have the same width. Since it is quite common for many characters
to have the same height, depth, or italic correction, the \.{TFM} format
imposes a limit of 16 different heights, 16 different depths, and
64 different italic corrections.

The italic correction of a character has two different uses.
(a)~In ordinary text, the italic correction is added to the width only if
the \TeX\ user specifies `\.{\\/}' after the character.
(b)~In math formulas, the italic correction is always added to the width,
except with respect to the positioning of subscripts.

Incidentally, the relation $\\{width}[0]=\\{height}[0]=\\{depth}[0]=
\\{italic}[0]=0$ should always hold, so that an index of zero implies a
value of zero.  The \\{width\_index} should never be zero unless the
character does not exist in the font, since a character is valid if and
only if it lies between \\{bc} and \\{ec} and has a nonzero \\{width\_index}.

\fi

\M544. The \\{tag} field in a \\{char\_info\_word} has four values that explain
how to
interpret the \\{remainder} field.

\yskip\hang$\\{tag}=0$ (\\{no\_tag}) means that \\{remainder} is unused.\par
\hang$\\{tag}=1$ (\\{lig\_tag}) means that this character has a
ligature/kerning
program starting at $\\{lig\_kern}[\\{remainder}]$.\par
\hang$\\{tag}=2$ (\\{list\_tag}) means that this character is part of a chain
of
characters of ascending sizes, and not the largest in the chain.  The
\\{remainder} field gives the character code of the next larger character.\par
\hang$\\{tag}=3$ (\\{ext\_tag}) means that this character code represents an
extensible character, i.e., a character that is built up of smaller pieces
so that it can be made arbitrarily large. The pieces are specified in
$\\{exten}[\\{remainder}]$.\par
\yskip\noindent
Characters with $\\{tag}=2$ and $\\{tag}=3$ are treated as characters with $%
\\{tag}=0$
unless they are used in special circumstances in math formulas. For example,
the \.{\\sum} operation looks for a \\{list\_tag}, and the \.{\\left}
operation looks for both \\{list\_tag} and \\{ext\_tag}.

\Y\P\D \37$\\{no\_tag}=0$\C{vanilla character}\par
\P\D \37$\\{lig\_tag}=1$\C{character has a ligature/kerning program}\par
\P\D \37$\\{list\_tag}=2$\C{character has a successor in a charlist}\par
\P\D \37$\\{ext\_tag}=3$\C{character is extensible}\par
\fi

\M545. The \\{lig\_kern} array contains instructions in a simple programming
language
that explains what to do for special letter pairs. Each word in this array is a
\\{lig\_kern\_command} of four bytes.

\yskip\hang first byte: \\{stop\_bit}, indicates that this is the final program
step if the byte is 128 or more.\par
\hang second byte: \\{next\_char}, ``if \\{next\_char} follows the current
character,
then perform the operation and stop, otherwise continue.''\par
\hang third byte: \\{op\_bit}, indicates a ligature step if less than~128,
a kern step otherwise.\par
\hang fourth byte: \\{remainder}.\par
\yskip\noindent
In a ligature step the current character and \\{next\_char} are replaced by
the single character whose code is \\{remainder}. In a kern step, an
additional space equal to $\\{kern}[\\{remainder}]$ is inserted between the
current character and \\{next\_char}. (The value of $\\{kern}[\\{remainder}]$
is
often negative, so that the characters are brought closer together
by kerning; but it might be positive.)

\Y\P\D \37$\\{stop\_flag}=128+\\{min\_quarterword}$\C{value indicating `%
\.{STOP}' in a lig/kern program}\par
\P\D \37$\\{kern\_flag}=128+\\{min\_quarterword}$\C{op code for a kern step}\par
\P\D \37$\\{stop\_bit}(\#)\S\#.\\{b0}$\par
\P\D \37$\\{next\_char}(\#)\S\#.\\{b1}$\par
\P\D \37$\\{op\_bit}(\#)\S\#.\\{b2}$\par
\P\D \37$\\{rem\_byte}(\#)\S\#.\\{b3}$\par
\fi

\M546. Extensible characters are specified by an \\{extensible\_recipe}, which
consists of four bytes called \\{top}, \\{mid}, \\{bot}, and \\{rep} (in this
order). These bytes are the character codes of individual pieces used to
build up a large symbol.  If \\{top}, \\{mid}, or \\{bot} are zero, they are
not
present in the built-up result. For example, an extensible vertical line is
like an extensible bracket, except that the top and bottom pieces are missing.

Let $T$, $M$, $B$, and $R$ denote the respective pieces, or an empty box
if the piece isn't present. Then the extensible characters have the form
$TR↑kMR↑kB$ from top to bottom, for some $\|k\G0$, unless $M$ is absent;
in the latter case we can have $TR↑kB$ for both even and odd values of~\|k.
The width of the extensible character is the width of $R$; and the
height-plus-depth is the sum of the individual height-plus-depths of the
components used, since the pieces are butted together in a vertical list.

\Y\P\D \37$\\{ext\_top}(\#)\S\#.\\{b0}$\C{\\{top} piece in a recipe}\par
\P\D \37$\\{ext\_mid}(\#)\S\#.\\{b1}$\C{\\{mid} piece in a recipe}\par
\P\D \37$\\{ext\_bot}(\#)\S\#.\\{b2}$\C{\\{bot} piece in a recipe}\par
\P\D \37$\\{ext\_rep}(\#)\S\#.\\{b3}$\C{\\{rep} piece in a recipe}\par
\fi

\M547. The final portion of a \.{TFM} file is the \\{param} array, which is
another
sequence of \\{fix\_word} values.

\yskip\hang$\\{param}[1]=\\{slant}$ is the amount of italic slant, which is
used
to help position accents. For example, $\\{slant}=.25$ means that when you go
up one unit, you also go .25 units to the right. The \\{slant} is a pure
number; it's the only \\{fix\_word} other than the design size itself that is
not scaled by the design size.

\hang$\\{param}[2]=\\{space}$ is the normal spacing between words in text.
Note that character \.{"\ "} in the font need not have anything to do with
blank spaces.

\hang$\\{param}[3]=\\{space\_stretch}$ is the amount of glue stretching between
words.

\hang$\\{param}[4]=\\{space\_shrink}$ is the amount of glue shrinking between
words.

\hang$\\{param}[5]=\\{x\_height}$ is the size of one ex in the font; it is also
the height of letters for which accents don't have to be raised or lowered.

\hang$\\{param}[6]=\\{quad}$ is the size of one em in the font.

\hang$\\{param}[7]=\\{extra\_space}$ is the amount added to $\\{param}[2]$ at
the
ends of sentences.

\yskip\noindent
If fewer than seven parameters are present, \TeX\ sets the missing parameters
to zero. Fonts used for math symbols are required to have
additional parameter information, which is explained later.

\Y\P\D \37$\\{slant\_code}=1$\par
\P\D \37$\\{space\_code}=2$\par
\P\D \37$\\{space\_stretch\_code}=3$\par
\P\D \37$\\{space\_shrink\_code}=4$\par
\P\D \37$\\{x\_height\_code}=5$\par
\P\D \37$\\{quad\_code}=6$\par
\P\D \37$\\{extra\_space\_code}=7$\par
\fi

\M548. So that is what \.{TFM} files hold. Since \TeX\ has to absorb such
information
about lots of fonts, it stores most of the data in a large array called
\\{font\_info}. Each item of \\{font\_info} is a \\{memory\_word}; the \\{fix%
\_word}
data gets converted into \\{scaled} entries, while everything else goes into
words of type \\{four\_quarters}.

When the user defines \.{\\font\\f}, say, \TeX\ assigns an internal number
to the user's font~\.{\\f}. Adding this number to \\{font\_id\_base} gives the
\\{eqtb} location of a ``frozen'' control sequence that will always select
the font.

\Y\P$\4\X18:Types in the outer block\X\mathrel{+}\S$\6
$\\{internal\_font\_number}=\\{font\_base}\to\\{font\_max}$;\C{\\{font} in a %
\\{char\_node}}\par
\fi

\M549. Here now is the (rather formidable) array of font arrays.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{font\_info}: \37\&{array} $[0\to\\{font\_mem\_size}]$ \1\&{of}\5
\\{memory\_word};\C{the big collection of font data}\2\6
\4\\{fmem\_ptr}: \37$0\to\\{font\_mem\_size}$;\C{first unused word of \\{font%
\_info}}\6
\4\\{font\_ptr}: \37\\{internal\_font\_number};\C{largest internal font number
in use}\6
\4\\{font\_check}: \37\&{array} $[\\{internal\_font\_number}]$ \1\&{of}\5
\\{four\_quarters};\C{check sum}\2\6
\4\\{font\_size}: \37\&{array} $[\\{internal\_font\_number}]$ \1\&{of}\5
\\{scaled};\C{``at'' size}\2\6
\4\\{font\_dsize}: \37\&{array} $[\\{internal\_font\_number}]$ \1\&{of}\5
\\{scaled};\C{``design'' size}\2\6
\4\\{font\_params}: \37\&{array} $[\\{internal\_font\_number}]$ \1\&{of}\5
\\{halfword};\C{how many font 	parameters are present}\2\6
\4\\{font\_name}: \37\&{array} $[\\{internal\_font\_number}]$ \1\&{of}\5
\\{str\_number};\C{name of the font}\2\6
\4\\{font\_area}: \37\&{array} $[\\{internal\_font\_number}]$ \1\&{of}\5
\\{str\_number};\C{area of the font}\2\6
\4\\{font\_bc}: \37\&{array} $[\\{internal\_font\_number}]$ \1\&{of}\5
\\{eight\_bits};\C{beginning (smallest) character code}\2\6
\4\\{font\_ec}: \37\&{array} $[\\{internal\_font\_number}]$ \1\&{of}\5
\\{eight\_bits};\C{ending (largest) character code}\2\6
\4\\{font\_glue}: \37\&{array} $[\\{internal\_font\_number}]$ \1\&{of}\5
\\{pointer};\C{glue specification for interword space, \\{null} if not
allocated}\2\6
\4\\{font\_used}: \37\&{array} $[\\{internal\_font\_number}]$ \1\&{of}\5
\\{boolean};\C{has a character from this font actually appeared in the output?}%
\2\6
\4\\{hyphen\_char}: \37\&{array} $[\\{internal\_font\_number}]$ \1\&{of}\5
\\{integer};\C{current \.{\\hyphenchar} values}\2\6
\4\\{skew\_char}: \37\&{array} $[\\{internal\_font\_number}]$ \1\&{of}\5
\\{integer};\C{current \.{\\skewchar} values}\2\par
\fi

\M550. Besides the arrays just enumerated, we have directory arrays that make
it
easy to get at the individual entries in \\{font\_info}. For example, the
\\{char\_info} data for character \|c in font \|f will be in
$\\{font\_info}[\\{char\_base}[\|f]+\|c].\\{qqqq}$; and if \|w is the \\{width%
\_index}
part of this word (the \\{b0} field), the width of the character is
$\\{font\_info}[\\{width\_base}[\|f]+\|w].\\{sc}$. (These formulas assume that
\\{min\_quarterword} has already been added to \|c and to \|w, since \TeX\
stores its quarterwords that way.)

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{char\_base}: \37\&{array} $[\\{internal\_font\_number}]$ \1\&{of}\5
\\{integer};\C{base addresses for \\{char\_info}}\2\6
\4\\{width\_base}: \37\&{array} $[\\{internal\_font\_number}]$ \1\&{of}\5
\\{integer};\C{base addresses for widths}\2\6
\4\\{height\_base}: \37\&{array} $[\\{internal\_font\_number}]$ \1\&{of}\5
\\{integer};\C{base addresses for heights}\2\6
\4\\{depth\_base}: \37\&{array} $[\\{internal\_font\_number}]$ \1\&{of}\5
\\{integer};\C{base addresses for depths}\2\6
\4\\{italic\_base}: \37\&{array} $[\\{internal\_font\_number}]$ \1\&{of}\5
\\{integer};\C{base addresses for italic corrections}\2\6
\4\\{lig\_kern\_base}: \37\&{array} $[\\{internal\_font\_number}]$ \1\&{of}\5
\\{integer};\C{base addresses for ligature/kerning programs}\2\6
\4\\{kern\_base}: \37\&{array} $[\\{internal\_font\_number}]$ \1\&{of}\5
\\{integer};\C{base addresses for kerns}\2\6
\4\\{exten\_base}: \37\&{array} $[\\{internal\_font\_number}]$ \1\&{of}\5
\\{integer};\C{base addresses for extensible recipes}\2\6
\4\\{param\_base}: \37\&{array} $[\\{internal\_font\_number}]$ \1\&{of}\5
\\{integer};\C{base addresses for font parameters}\2\par
\fi

\M551. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
\&{for} $\|k\K\\{font\_base}\mathrel{\&{to}}\\{font\_max}$ \1\&{do}\5
$\\{font\_used}[\|k]\K\\{false}$;\2\par
\fi

\M552. \TeX\ always knows at least one font, namely the null font. It has no
characters, and its seven parameters are all equal to zero.

\Y\P$\4\X164:Initialize table entries (done by \.{INITEX} only)\X\mathrel{+}\S$%
\6
$\\{font\_ptr}\K\\{null\_font}$;\5
$\\{fmem\_ptr}\K7$;\5
$\\{font\_name}[\\{null\_font}]\K\.{"nullfont"}$;\5
$\\{font\_area}[\\{null\_font}]\K\.{""}$;\5
$\\{hyphen\_char}[\\{null\_font}]\K\.{"-"}$;\5
$\\{skew\_char}[\\{null\_font}]\K-1$;\5
$\\{font\_bc}[\\{null\_font}]\K1$;\5
$\\{font\_ec}[\\{null\_font}]\K0$;\5
$\\{font\_size}[\\{null\_font}]\K0$;\5
$\\{font\_dsize}[\\{null\_font}]\K0$;\5
$\\{char\_base}[\\{null\_font}]\K0$;\5
$\\{width\_base}[\\{null\_font}]\K0$;\5
$\\{height\_base}[\\{null\_font}]\K0$;\5
$\\{depth\_base}[\\{null\_font}]\K0$;\5
$\\{italic\_base}[\\{null\_font}]\K0$;\5
$\\{lig\_kern\_base}[\\{null\_font}]\K0$;\5
$\\{kern\_base}[\\{null\_font}]\K0$;\5
$\\{exten\_base}[\\{null\_font}]\K0$;\5
$\\{font\_glue}[\\{null\_font}]\K\\{null}$;\5
$\\{font\_params}[\\{null\_font}]\K7$;\5
$\\{param\_base}[\\{null\_font}]\K-1$;\6
\&{for} $\|k\K0\mathrel{\&{to}}6$ \1\&{do}\5
$\\{font\_info}[\|k].\\{sc}\K0$;\2\par
\fi

\M553. \P$\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}%
\S$\6
$\\{primitive}(\.{"nullfont"},\39\\{set\_font},\39\\{null\_font})$;\5
$\\{text}(\\{frozen\_null\_font})\K\.{"nullfont"}$;\5
$\\{eqtb}[\\{frozen\_null\_font}]\K\\{eqtb}[\\{cur\_val}]$;\par
\fi

\M554. Of course we want to define macros that suppress the detail of how font
information is actually packed, so that we don't have to write things like
$$\hbox{$\\{font\_info}[\\{width\_base}[\|f]+\\{font\_info}[\\{char\_base}[%
\|f]+\|c].\\{qqqq}.\\{b0}].\\{sc}$}$$
too often. The \.{WEB} definitions here make $\\{char\_info}(\|f)(\|c)$ the
\\{four\_quarters} word of font information corresponding to character
\|c of font \|f. If \|q is such a word, $\\{char\_width}(\|f)(\|q)$ will be
the character's width; hence the long formula above is at least
abbreviated to
$$\hbox{$\\{char\_width}(\|f)(\\{char\_info}(\|f)(\|c))$.}$$
Usually, of course, we will fetch \|q first and look at several of its
fields at the same time.

The italic correction of a character will be denoted by
$\\{char\_italic}(\|f)(\|q)$, so it is analogous to \\{char\_width}.  But we
will get
at the height and depth in a slightly different way, since we usually want
to compute both height and depth if we want either one.  The value of
$\\{height\_depth}(\|q)$ will be the 8-bit quantity
$$b=\\{height\_index}\times16+\\{depth\_index},$$ and if \|b is such a byte we
will write $\\{char\_height}(\|f)(\|b)$ and $\\{char\_depth}(\|f)(\|b)$ for the
height and
depth of the character \|c for which $\|q=\\{char\_info}(\|f)(\|c)$. Got that?

The tag field will be called $\\{char\_tag}(\|q)$; the remainder byte will be
called $\\{rem\_byte}(\|q)$, using a macro that we have already defined above.

Access to a character's \\{width}, \\{height}, \\{depth}, and \\{tag} fields is
part of \TeX's inner loop, so we want these macros to produce code that is
as fast as possible under the circumstances.

\Y\P\D \37$\\{char\_info\_end}(\#)\S\#$ ] .\\{qqqq}\par
\P\D $\\{char\_info}(\#)\S\\{font\_info}$ [ $\\{char\_base}[\#]+\\{char\_info%
\_end}$\par
\P\D \37$\\{char\_width\_end}(\#)\S\#.\\{b0}$ ] .\\{sc}\par
\P\D $\\{char\_width}(\#)\S\\{font\_info}$ [ $\\{width\_base}[\#]+\\{char%
\_width\_end}$\par
\P\D \37$\\{char\_exists}(\#)\S(\#.\\{b0}>\\{min\_quarterword})$\par
\P\D \37$\\{char\_italic\_end}(\#)\S(\\{qo}(\#.\\{b2}))\mathbin{\&{div}}4$ ] .%
\\{sc}\par
\P\D $\\{char\_italic}(\#)\S\\{font\_info}$ [ $\\{italic\_base}[\#]+\\{char%
\_italic\_end}$\par
\P\D \37$\\{height\_depth}(\#)\S\\{qo}(\#.\\{b1})$\par
\P\D \37$\\{char\_height\_end}(\#)\S(\#)\mathbin{\&{div}}16$ ] .\\{sc}\par
\P\D $\\{char\_height}(\#)\S\\{font\_info}$ [ $\\{height\_base}[\#]+\\{char%
\_height\_end}$\par
\P\D \37$\\{char\_depth\_end}(\#)\S(\#)\mathbin{\&{mod}}16$ ] .\\{sc}\par
\P\D $\\{char\_depth}(\#)\S\\{font\_info}$ [ $\\{depth\_base}[\#]+\\{char%
\_depth\_end}$\par
\P\D \37$\\{char\_tag}(\#)\S((\\{qo}(\#.\\{b2}))\mathbin{\&{mod}}4)$\par
\fi

\M555. The global variable \\{null\_character} is set up to be a word of
\\{char\_info} for a character that doesn't exist. Such a word provides a
convenient way to deal with erroneous situations.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{null\_character}: \37\\{four\_quarters};\C{nonexistent character
information}\par
\fi

\M556. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{null\_character}.\\{b0}\K\\{min\_quarterword}$;\5
$\\{null\_character}.\\{b1}\K\\{min\_quarterword}$;\5
$\\{null\_character}.\\{b2}\K\\{min\_quarterword}$;\5
$\\{null\_character}.\\{b3}\K\\{min\_quarterword}$;\par
\fi

\M557. Here are some macros that help process ligatures and kerns.
We write $\\{char\_kern}(\|f)(\|j)$ to find the amount of kerning specified by
kerning command~\|j in font~\|f.

\Y\P\D \37$\\{lig\_kern\_start}(\#)\S\\{lig\_kern\_base}[\#]+\\{rem\_byte}$%
\C{beginning of lig/kern program}\par
\P\D \37$\\{char\_kern\_end}(\#)\S\\{rem\_byte}(\#)$ ] .\\{sc}\par
\P\D $\\{char\_kern}(\#)\S\\{font\_info}$ [ $\\{kern\_base}[\#]+\\{char\_kern%
\_end}$\par
\fi

\M558. Font parameters are referred to as $\\{slant}(\|f)$, $\\{space}(\|f)$,
etc.

\Y\P\D \37$\\{param\_end}(\#)\S\\{param\_base}[\#]$ ] .\\{sc}\par
\P\D $\\{param}(\#)\S\\{font\_info}$ [ $\#+\\{param\_end}$\par
\P\D \37$\\{slant}\S\\{param}(\\{slant\_code})$\C{slant to the right, per unit
distance upward}\par
\P\D \37$\\{space}\S\\{param}(\\{space\_code})$\C{normal space between words}%
\par
\P\D \37$\\{space\_stretch}\S\\{param}(\\{space\_stretch\_code})$\C{stretch
between words}\par
\P\D \37$\\{space\_shrink}\S\\{param}(\\{space\_shrink\_code})$\C{shrink
between words}\par
\P\D \37$\\{x\_height}\S\\{param}(\\{x\_height\_code})$\C{one ex}\par
\P\D \37$\\{quad}\S\\{param}(\\{quad\_code})$\C{one em}\par
\P\D \37$\\{extra\_space}\S\\{param}(\\{extra\_space\_code})$\C{additional
space at end of sentence}\par
\Y\P$\4\X558:The em width for \\{cur\_font}\X\S$\6
$\\{quad}(\\{cur\_font})$\par
\U section~455.\fi

\M559. \P$\X559:The x-height for \\{cur\_font}\X\S$\6
$\\{x\_height}(\\{cur\_font})$\par
\U section~455.\fi

\M560. \TeX\ checks the information of a \.{TFM} file for validity as the
file is being read in, so that no further checks will be needed when
typesetting is going on. The somewhat tedious subroutine that does this
is called \\{read\_font\_info}. It has four parameters: the user font
identifier~\|u, the file name and area strings \\{nom} and \\{aire}, and the
``at'' size~\|s. If \|s~is negative, it's the negative of a scale factor
to be applied to the design size; $\|s=-1000$ is the normal case.
Otherwise \|s will be substituted for the design size; in this
case, \|s must be positive and less than $2048\rm\,pt$
(i.e., it must be less than $2↑{27}$ when considered as an integer).

The subroutine opens and closes a global file variable called \\{tfm\_file}.
It returns the value of the internal font number that was just loaded.
If an error is detected, an error message is issued and no font
information is stored; \\{null\_font} is returned in this case.

\Y\P\D \37$\\{bad\_tfm}=11$\C{label for \\{read\_font\_info}}\par
\P\D \37$\\{abort}\S$\1\5
\&{goto} \37\\{bad\_tfm}\C{do this when the \.{TFM} data is wrong}\2\par
\Y\P\4\&{function}\1\  \37$\\{read\_font\_info}(\|u:\\{pointer};\,\35\\{nom},%
\39\\{aire}:\\{str\_number};\,\35\|s:\\{scaled})$: \37\\{internal\_font%
\_number};\C{input a \.{TFM} file}\6
\4\&{label} \37$\\{done},\39\\{bad\_tfm},\39\\{not\_found}$;\6
\4\&{var} \37\|k: \37$0\to\\{font\_mem\_size}$;\C{index into \\{font\_info}}\6
\\{file\_opened}: \37\\{boolean};\C{was \\{tfm\_file} successfully opened?}\6
$\\{lf},\39\\{lh},\39\\{bc},\39\\{ec},\39\\{nw},\39\\{nh},\39\\{nd},\39\\{ni},%
\39\\{nl},\39\\{nk},\39\\{ne},\39\\{np}$: \37\\{halfword};\C{sizes of subfiles}%
\6
\|f: \37\\{internal\_font\_number};\C{the new font's number}\6
\|g: \37\\{internal\_font\_number};\C{the number to return}\6
$\|a,\39\|b,\39\|c,\39\|d$: \37\\{eight\_bits};\C{byte variables}\6
\\{qw}: \37\\{four\_quarters};\5
\\{sw}: \37\\{scaled};\C{accumulators}\6
\|z: \37\\{scaled};\C{the design size or the ``at'' size}\6
\\{alpha}: \37\\{integer};\5
\\{beta}: \37$1\to16$;\C{auxiliary quantities used in fixed-point
multiplication}\2\6
\&{begin} \37$\|g\K\\{null\_font}$;\6
\X562:Read and check the font data; \\{abort} if the \.{TFM} file is malformed;
if there's no room for this font, say so and \&{goto} \\{done}; otherwise $%
\\{incr}(\\{font\_ptr})$ and \&{goto} \\{done}\X;\6
\4\\{bad\_tfm}: \37\X561:Report that the font won't be loaded\X;\6
\4\\{done}: \37\&{if} $\\{file\_opened}$ \1\&{then}\5
$\\{b\_close}(\\{tfm\_file})$;\2\6
$\\{read\_font\_info}\K\|g$;\6
\&{end};\par
\fi

\M561. There are programs called \.{TFtoPL} and \.{PLtoTF} that convert
between the \.{TFM} format and a symbolic property-list format
that can be easily edited. These programs contain extensive
diagnostic information, so \TeX\ does not have to bother giving
precise details about why it rejects a particular \.{TFM} file.

\Y\P\D \37$\\{start\_font\_error\_message}\S\\{print\_err}(\.{"Font\ "})$;\5
$\\{sprint\_cs}(\|u)$;\5
$\\{print\_char}(\.{"="})$;\5
$\\{print\_file\_name}(\\{nom},\39\\{aire},\39\.{""})$;\6
\&{if} $\|s\G0$ \1\&{then}\6
\&{begin} \37$\\{print}(\.{"\ at\ "})$;\5
$\\{print\_scaled}(\|s)$;\5
$\\{print}(\.{"pt"})$;\6
\&{end}\6
\4\&{else} \&{if} $\|s\I-1000$ \1\&{then}\6
\&{begin} \37$\\{print}(\.{"\ scaled\ "})$;\5
$\\{print\_int}(-\|s)$;\6
\&{end}\2\2\par
\Y\P$\4\X561:Report that the font won't be loaded\X\S$\6
\\{start\_font\_error\_message};\6
\&{if} $\\{file\_opened}$ \1\&{then}\5
$\\{print}(\.{"\ not\ loadable:\ Bad\ metric\ (TFM)\ file"})$\6
\4\&{else} $\\{print}(\.{"\ not\ loadable:\ Metric\ (TFM)\ file\ not\
found"})$;\2\6
$\\{help5}(\.{"I\ wasn\'t\ able\ to\ read\ the\ size\ data\ for\ this\
font,"})$\6
$(\.{"so\ I\ will\ ignore\ the\ font\ specification."})$\6
$(\.{"[Wizards\ can\ fix\ TFM\ files\ using\ TFtoPL/PLtoTF.]"})$\6
$(\.{"You\ might\ try\ inserting\ a\ different\ font\ spec;"})$\6
$(\.{"e.g.,\ type\ \`I\\font<same\ font\ id>=<substitute\ font\ name>\'."})$;\5
\\{error}\par
\U section~560.\fi

\M562. \P$\X562:Read and check the font data; \\{abort} if the \.{TFM} file is
malformed; if there's no room for this font, say so and \&{goto} \\{done};
otherwise $\\{incr}(\\{font\_ptr})$ and \&{goto} \\{done}\X\S$\6
\X563:Open \\{tfm\_file} for input\X;\6
\X565:Read the {\.{TFM}} size fields\X;\6
\X566:Use size fields to allocate font information\X;\6
\X568:Read the {\.{TFM}} header\X;\6
\X569:Read character data\X;\6
\X571:Read box dimensions\X;\6
\X573:Read ligature/kern program\X;\6
\X574:Read extensible character recipes\X;\6
\X575:Read font parameters\X;\6
\X576:Make final adjustments and \&{goto} \\{done}\X\par
\U section~560.\fi

\M563. \P$\X563:Open \\{tfm\_file} for input\X\S$\6
$\\{file\_opened}\K\\{false}$;\6
\&{if} $\\{aire}=\.{""}$ \1\&{then}\5
$\\{pack\_file\_name}(\\{nom},\39\\{TEX\_font\_area},\39\.{".tfm"})$\6
\4\&{else} $\\{pack\_file\_name}(\\{nom},\39\\{aire},\39\.{".tfm"})$;\2\6
\&{if} $\R\\{b\_open\_in}(\\{tfm\_file})$ \1\&{then}\5
\\{abort};\2\6
$\\{file\_opened}\K\\{true}$\par
\U section~562.\fi

\M564. Note: A malformed \.{TFM} file might be shorter than it claims to be;
thus $\\{eof}(\\{tfm\_file})$ might be true when \\{read\_font\_info} refers to
$\\{tfm\_file}\↑$ or when it says $\\{get}(\\{tfm\_file})$. If such
circumstances
cause system error messages, you will have to defeat them somehow,
for example by defining \\{fget} to be `\ignorespaces \&{begin} $\\{get}(\\{tfm%
\_file})$;
 \&{if} $\\{eof}(\\{tfm\_file})$ \&{then} \\{abort}; \&{end} \unskip'.

\Y\P\D \37$\\{fget}\S\\{get}(\\{tfm\_file})$\par
\P\D \37$\\{fbyte}\S\\{tfm\_file}\↑$\par
\P\D \37$\\{read\_sixteen}(\#)\S$\1\6
\&{begin} \37$\#\K\\{fbyte}$;\6
\&{if} $\#>127$ \1\&{then}\5
\\{abort};\2\6
\\{fget};\5
$\#\K\#\ast\O{400}+\\{fbyte}$;\6
\&{end}\2\par
\P\D \37$\\{store\_four\_quarters}(\#)\S$\1\6
\&{begin} \37\\{fget};\5
$\|a\K\\{fbyte}$;\5
$\\{qw}.\\{b0}\K\\{qi}(\|a)$;\5
\\{fget};\5
$\|b\K\\{fbyte}$;\5
$\\{qw}.\\{b1}\K\\{qi}(\|b)$;\5
\\{fget};\5
$\|c\K\\{fbyte}$;\5
$\\{qw}.\\{b2}\K\\{qi}(\|c)$;\5
\\{fget};\5
$\|d\K\\{fbyte}$;\5
$\\{qw}.\\{b3}\K\\{qi}(\|d)$;\5
$\#\K\\{qw}$;\6
\&{end}\2\par
\fi

\M565. \P$\X565:Read the {\.{TFM}} size fields\X\S$\6
\&{begin} \37$\\{read\_sixteen}(\\{lf})$;\5
\\{fget};\5
$\\{read\_sixteen}(\\{lh})$;\5
\\{fget};\5
$\\{read\_sixteen}(\\{bc})$;\5
\\{fget};\5
$\\{read\_sixteen}(\\{ec})$;\6
\&{if} $(\\{bc}>\\{ec}+1)\V(\\{ec}>255)$ \1\&{then}\5
\\{abort};\2\6
\\{fget};\5
$\\{read\_sixteen}(\\{nw})$;\5
\\{fget};\5
$\\{read\_sixteen}(\\{nh})$;\5
\\{fget};\5
$\\{read\_sixteen}(\\{nd})$;\5
\\{fget};\5
$\\{read\_sixteen}(\\{ni})$;\5
\\{fget};\5
$\\{read\_sixteen}(\\{nl})$;\5
\\{fget};\5
$\\{read\_sixteen}(\\{nk})$;\5
\\{fget};\5
$\\{read\_sixteen}(\\{ne})$;\5
\\{fget};\5
$\\{read\_sixteen}(\\{np})$;\6
\&{if} $\\{lf}\I6+\\{lh}+(\\{ec}-\\{bc}+1)+\\{nw}+\\{nh}+\\{nd}+\\{ni}+\\{nl}+%
\\{nk}+\\{ne}+\\{np}$ \1\&{then}\5
\\{abort};\2\6
\&{end}\par
\U section~562.\fi

\M566. The preliminary settings of the index variables \\{char\_base},
\\{width\_base}, \\{lig\_kern\_base}, \\{kern\_base}, and \\{exten\_base} will
be
corrected later by subtracting \\{min\_quarterword} from them; and we will
subtract 1 from \\{param\_base} too. It's best to forget about such anomalies
until later.

\Y\P$\4\X566:Use size fields to allocate font information\X\S$\6
$\\{lf}\K\\{lf}-6-\\{lh}$;\C{\\{lf} words should be loaded into \\{font\_info}}%
\6
\&{if} $\\{np}<7$ \1\&{then}\5
$\\{lf}\K\\{lf}+7-\\{np}$;\C{at least seven parameters will appear}\2\6
\&{if} $(\\{font\_ptr}=\\{font\_max})\V(\\{fmem\_ptr}+\\{lf}>\\{font\_mem%
\_size})$ \1\&{then}\5
\X567:Apologize for not loading the font, \&{goto} \\{done}\X;\2\6
$\|f\K\\{font\_ptr}+1$;\5
$\\{char\_base}[\|f]\K\\{fmem\_ptr}-\\{bc}$;\5
$\\{width\_base}[\|f]\K\\{char\_base}[\|f]+\\{ec}+1$;\5
$\\{height\_base}[\|f]\K\\{width\_base}[\|f]+\\{nw}$;\5
$\\{depth\_base}[\|f]\K\\{height\_base}[\|f]+\\{nh}$;\5
$\\{italic\_base}[\|f]\K\\{depth\_base}[\|f]+\\{nd}$;\5
$\\{lig\_kern\_base}[\|f]\K\\{italic\_base}[\|f]+\\{ni}$;\5
$\\{kern\_base}[\|f]\K\\{lig\_kern\_base}[\|f]+\\{nl}$;\5
$\\{exten\_base}[\|f]\K\\{kern\_base}[\|f]+\\{nk}$;\5
$\\{param\_base}[\|f]\K\\{exten\_base}[\|f]+\\{ne}$\par
\U section~562.\fi

\M567. \P$\X567:Apologize for not loading the font, \&{goto} \\{done}\X\S$\6
\&{begin} \37\\{start\_font\_error\_message};\5
$\\{print}(\.{"\ not\ loaded:\ Not\ enough\ room\ left"})$;\5
$\\{help4}(\.{"I\'m\ afraid\ I\ won\'t\ be\ able\ to\ make\ use\ of\ this\
font,"})$\6
$(\.{"because\ my\ memory\ for\ character-size\ data\ is\ too\ small."})$\6
$(\.{"If\ you\'re\ really\ stuck,\ ask\ a\ wizard\ to\ enlarge\ me."})$\6
$(\.{"Or\ maybe\ try\ \`I\\font<same\ font\ id>=<name\ of\ loaded\ font>%
\'."})$;\5
\\{error};\5
\&{goto} \37\\{done};\6
\&{end}\par
\U section~566.\fi

\M568. Only the first two words of the header are needed by \TeX82.

\Y\P$\4\X568:Read the {\.{TFM}} header\X\S$\6
\&{begin} \37\&{if} $\\{lh}<2$ \1\&{then}\5
\\{abort};\2\6
$\\{store\_four\_quarters}(\\{font\_check}[\|f])$;\5
\\{fget};\5
$\\{read\_sixteen}(\|z)$;\C{this rejects a negative design size}\6
\\{fget};\5
$\|z\K\|z\ast\O{400}+\\{fbyte}$;\5
\\{fget};\5
$\|z\K(\|z\ast\O{20})+(\\{fbyte}\mathbin{\&{div}}\O{20})$;\6
\&{if} $\|z<\\{unity}$ \1\&{then}\5
\\{abort};\2\6
\&{while} $\\{lh}>2$ \1\&{do}\6
\&{begin} \37\\{fget};\5
\\{fget};\5
\\{fget};\5
\\{fget};\5
$\\{decr}(\\{lh})$;\C{ignore the rest of the header}\6
\&{end};\2\6
$\\{font\_dsize}[\|f]\K\|z$;\6
\&{if} $\|s\I-1000$ \1\&{then}\6
\&{if} $\|s\G0$ \1\&{then}\5
$\|z\K\|s$\6
\4\&{else} $\|z\K\\{xn\_over\_d}(\|z,\39-\|s,\391000)$;\2\2\6
$\\{font\_size}[\|f]\K\|z$;\6
\&{end}\par
\U section~562.\fi

\M569. \P$\X569:Read character data\X\S$\6
\&{for} $\|k\K\\{fmem\_ptr}\mathrel{\&{to}}\\{width\_base}[\|f]-1$ \1\&{do}\6
\&{begin} \37$\\{store\_four\_quarters}(\\{font\_info}[\|k].\\{qqqq})$;\6
\&{if} $(\|a\G\\{nw})\V(\|b\mathbin{\&{div}}\O{20}\G\\{nh})\V(\|b\mathbin{%
\&{mod}}\O{20}\G\\{nd})\V(\|c\mathbin{\&{div}}4\G\\{ni})$ \1\&{then}\5
\\{abort};\2\6
\&{case} $\|c\mathbin{\&{mod}}4$ \1\&{of}\6
\4\\{lig\_tag}: \37\&{if} $\|d\G\\{nl}$ \1\&{then}\5
\\{abort};\2\6
\4\\{ext\_tag}: \37\&{if} $\|d\G\\{ne}$ \1\&{then}\5
\\{abort};\2\6
\4\\{list\_tag}: \37\X570:Check for charlist cycle\X;\6
\4\&{othercases} \37\\{do\_nothing}\C{\\{no\_tag}}\2\6
\&{endcases};\6
\&{end}\2\par
\U section~562.\fi

\M570. We want to make sure that there is no cycle of characters linked
together
by \\{list\_tag} entries, since such a cycle would get \TeX\ into an endless
loop. If such a cycle exists, the routine here detects it when processing
the largest character code in the cycle.

\Y\P\D \37$\\{check\_byte\_range}(\#)\S$\1\6
\&{begin} \37\&{if} $(\#<\\{bc})\V(\#>\\{ec})$ \1\&{then}\5
\\{abort}\ \2\6
\&{end}\2\par
\P\D \37$\\{current\_character\_being\_worked\_on}\S\|k+\\{bc}-\\{fmem\_ptr}$%
\par
\Y\P$\4\X570:Check for charlist cycle\X\S$\6
\&{begin} \37$\\{check\_byte\_range}(\|d)$;\6
\&{while} $\|d<\\{current\_character\_being\_worked\_on}$ \1\&{do}\6
\&{begin} \37$\\{qw}\K\\{char\_info}(\|f)(\|d)$;\C{N.B.: not $\\{qi}(\|d)$,
since $\\{char\_base}[\|f]$ hasn't been adjusted yet}\6
\&{if} $\\{char\_tag}(\\{qw})\I\\{list\_tag}$ \1\&{then}\5
\&{goto} \37\\{not\_found};\2\6
$\|d\K\\{qo}(\\{rem\_byte}(\\{qw}))$;\C{next character on the list}\6
\&{end};\2\6
\&{if} $\|d=\\{current\_character\_being\_worked\_on}$ \1\&{then}\5
\\{abort};\C{yes, there's a cycle}\2\6
\4\\{not\_found}: \37\&{end}\par
\U section~569.\fi

\M571. A \\{fix\_word} whose four bytes are $(a,b,c,d)$ from left to right
represents
the number
$$x=\left\{\vcenter{\halign{$#$,\hfil\qquad&if $#$\hfil\cr
b\cdot2↑{-4}+c\cdot2↑{-12}+d\cdot2↑{-20}&a=0;\cr
-16+b\cdot2↑{-4}+c\cdot2↑{-12}+d\cdot2↑{-20}&a=255.\cr}}\right.$$
(No other choices of \|a are allowed, since the magnitude of a number in
design-size units must be less than 16.)  We want to multiply this
quantity by the integer~\|z, which is known to be less than $2↑{27}$. Let
$\alpha=16z$.  If $\|z<2↑{23}$, the individual multiplications $b\cdot z$,
$c\cdot z$, $d\cdot z$ cannot overflow; otherwise we will divide \|z by 2,
4, 8, or 16, to obtain a multiplier less than $2↑{23}$, and we can
compensate for this later. If \|z has thereby been replaced by
$\|z↑\prime=\|z/2↑e$, let $\beta=2↑{4-e}$; we shall compute
$$\lfloor(b+c\cdot2↑{-8}+d\cdot2↑{-16})\,z↑\prime/\beta\rfloor$$
if $a=0$, or the same quantity minus $\alpha$ if $a=255$.
This calculation must be done exactly, in order to guarantee portability
of \TeX\ between computers.

\Y\P\D \37$\\{store\_scaled}(\#)\S$\1\6
\&{begin} \37\\{fget};\5
$\|a\K\\{fbyte}$;\5
\\{fget};\5
$\|b\K\\{fbyte}$;\5
\\{fget};\5
$\|c\K\\{fbyte}$;\5
\\{fget};\5
$\|d\K\\{fbyte}$;\6
$\\{sw}\K(((((\|d\ast\|z)\mathbin{\&{div}}\O{400})+(\|c\ast\|z))\mathbin{%
\&{div}}\O{400})+(\|b\ast\|z))\mathbin{\&{div}}\\{beta}$;\6
\&{if} $\|a=0$ \1\&{then}\5
$\#\K\\{sw}$\ \&{else} \&{if} $\|a=255$ \1\&{then}\5
$\#\K\\{sw}-\\{alpha}$\ \&{else} \\{abort};\2\2\6
\&{end}\2\par
\Y\P$\4\X571:Read box dimensions\X\S$\6
\&{begin} \37\X572:Replace \|z by $\|z↑\prime$ and compute $\alpha,\beta$\X;\6
\&{for} $\|k\K\\{width\_base}[\|f]\mathrel{\&{to}}\\{lig\_kern\_base}[\|f]-1$ %
\1\&{do}\5
$\\{store\_scaled}(\\{font\_info}[\|k].\\{sc})$;\2\6
\&{if} $\\{font\_info}[\\{width\_base}[\|f]].\\{sc}\I0$ \1\&{then}\5
\\{abort};\C{\\{width}[0] must be zero}\2\6
\&{if} $\\{font\_info}[\\{height\_base}[\|f]].\\{sc}\I0$ \1\&{then}\5
\\{abort};\C{\\{height}[0] must be zero}\2\6
\&{if} $\\{font\_info}[\\{depth\_base}[\|f]].\\{sc}\I0$ \1\&{then}\5
\\{abort};\C{\\{depth}[0] must be zero}\2\6
\&{if} $\\{font\_info}[\\{italic\_base}[\|f]].\\{sc}\I0$ \1\&{then}\5
\\{abort};\C{\\{italic}[0] must be zero}\2\6
\&{end}\par
\U section~562.\fi

\M572. \P$\X572:Replace \|z by $\|z↑\prime$ and compute $\alpha,\beta$\X\S$\6
\&{begin} \37$\\{alpha}\K16\ast\|z$;\5
$\\{beta}\K16$;\6
\&{while} $\|z\G\O{40000000}$ \1\&{do}\6
\&{begin} \37$\|z\K\|z\mathbin{\&{div}}2$;\5
$\\{beta}\K\\{beta}\mathbin{\&{div}}2$;\6
\&{end};\2\6
\&{end}\par
\U section~571.\fi

\M573. \P$\X573:Read ligature/kern program\X\S$\6
\&{begin} \37\&{for} $\|k\K\\{lig\_kern\_base}[\|f]\mathrel{\&{to}}\\{kern%
\_base}[\|f]-1$ \1\&{do}\6
\&{begin} \37$\\{store\_four\_quarters}(\\{font\_info}[\|k].\\{qqqq})$;\5
$\\{check\_byte\_range}(\|b)$;\6
\&{if} $\|c<128$ \1\&{then}\5
$\\{check\_byte\_range}(\|d)$\C{check ligature}\6
\4\&{else} \&{if} $\|d\G\\{nk}$ \1\&{then}\5
\\{abort};\C{check kern}\2\2\6
\&{end};\2\6
\&{if} $(\\{nl}>0)\W(\|a<128)$ \1\&{then}\5
\\{abort};\C{check for stop bit on last command}\2\6
\&{for} $\|k\K\\{kern\_base}[\|f]\mathrel{\&{to}}\\{exten\_base}[\|f]-1$ \1%
\&{do}\5
$\\{store\_scaled}(\\{font\_info}[\|k].\\{sc})$;\2\6
\&{end}\par
\U section~562.\fi

\M574. \P$\X574:Read extensible character recipes\X\S$\6
\&{for} $\|k\K\\{exten\_base}[\|f]\mathrel{\&{to}}\\{param\_base}[\|f]-1$ \1%
\&{do}\6
\&{begin} \37$\\{store\_four\_quarters}(\\{font\_info}[\|k].\\{qqqq})$;\6
\&{if} $\|a\I0$ \1\&{then}\5
$\\{check\_byte\_range}(\|a)$;\2\6
\&{if} $\|b\I0$ \1\&{then}\5
$\\{check\_byte\_range}(\|b)$;\2\6
\&{if} $\|c\I0$ \1\&{then}\5
$\\{check\_byte\_range}(\|c)$;\2\6
$\\{check\_byte\_range}(\|d)$;\6
\&{end}\2\par
\U section~562.\fi

\M575. We check to see that the \.{TFM} file doesn't end prematurely; but
no error message is given for files having more than \\{lf} words.

\Y\P$\4\X575:Read font parameters\X\S$\6
\&{begin} \37\&{for} $\|k\K1\mathrel{\&{to}}\\{np}$ \1\&{do}\6
\&{if} $\|k=1$ \1\&{then}\C{the \\{slant} parameter is a pure number}\6
\&{begin} \37\\{fget};\5
$\\{sw}\K\\{fbyte}$;\6
\&{if} $\\{sw}>127$ \1\&{then}\5
$\\{sw}\K\\{sw}-256$;\2\6
\\{fget};\5
$\\{sw}\K\\{sw}\ast\O{400}+\\{fbyte}$;\5
\\{fget};\5
$\\{sw}\K\\{sw}\ast\O{400}+\\{fbyte}$;\5
\\{fget};\5
$\\{font\_info}[\\{param\_base}[\|f]].\\{sc}\K(\\{sw}\ast\O{20})+(\\{fbyte}%
\mathbin{\&{div}}\O{20})$;\6
\&{end}\6
\4\&{else} $\\{store\_scaled}(\\{font\_info}[\\{param\_base}[\|f]+\|k-1].%
\\{sc})$;\2\2\6
\&{if} $\\{eof}(\\{tfm\_file})$ \1\&{then}\5
\\{abort};\2\6
\&{for} $\|k\K\\{np}+1\mathrel{\&{to}}7$ \1\&{do}\5
$\\{font\_info}[\\{param\_base}[\|f]+\|k-1].\\{sc}\K0$;\2\6
\&{end}\par
\U section~562.\fi

\M576. Now to wrap it up, we have checked all the necessary things about the %
\.{TFM}
file, and all we need to do is put the finishing touches on the data for
the new font.

\Y\P\D \37$\\{adjust}(\#)\S\#[\|f]\K\\{qo}(\#[\|f])$\C{correct for the excess %
\\{min\_quarterword} that was added}\par
\Y\P$\4\X576:Make final adjustments and \&{goto} \\{done}\X\S$\6
\&{if} $\\{np}\G7$ \1\&{then}\5
$\\{font\_params}[\|f]\K\\{np}$\ \&{else} $\\{font\_params}[\|f]\K7$;\2\6
$\\{hyphen\_char}[\|f]\K\\{default\_hyphen\_char}$;\5
$\\{skew\_char}[\|f]\K\\{default\_skew\_char}$;\5
$\\{font\_name}[\|f]\K\\{nom}$;\5
$\\{font\_area}[\|f]\K\\{aire}$;\5
$\\{font\_bc}[\|f]\K\\{bc}$;\5
$\\{font\_ec}[\|f]\K\\{ec}$;\5
$\\{font\_glue}[\|f]\K\\{null}$;\5
$\\{adjust}(\\{char\_base})$;\5
$\\{adjust}(\\{width\_base})$;\5
$\\{adjust}(\\{lig\_kern\_base})$;\5
$\\{adjust}(\\{kern\_base})$;\5
$\\{adjust}(\\{exten\_base})$;\5
$\\{decr}(\\{param\_base}[\|f])$;\5
$\\{fmem\_ptr}\K\\{fmem\_ptr}+\\{lf}$;\5
$\\{font\_ptr}\K\|f$;\5
$\|g\K\|f$;\5
\&{goto} \37\\{done}\par
\U section~562.\fi

\M577. Before we forget about the format of these tables, let's deal with two
of \TeX's basic scanning routines related to font information.

\Y\P$\4\X577:Declare procedures that scan font-related stuff\X\S$\6
\4\&{procedure}\1\  \37\\{scan\_font\_ident};\6
\4\&{var} \37\|f: \37\\{internal\_font\_number};\5
\|m: \37\\{halfword};\2\6
\&{begin} \37\X406:Get the next non-blank non-call token\X;\6
\&{if} $\\{cur\_cmd}=\\{def\_font}$ \1\&{then}\5
$\|f\K\\{cur\_font}$\6
\4\&{else} \&{if} $\\{cur\_cmd}=\\{set\_font}$ \1\&{then}\5
$\|f\K\\{cur\_chr}$\6
\4\&{else} \&{if} $\\{cur\_cmd}=\\{def\_family}$ \1\&{then}\6
\&{begin} \37$\|m\K\\{cur\_chr}$;\5
\\{scan\_four\_bit\_int};\5
$\|f\K\\{equiv}(\|m+\\{cur\_val})$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{print\_err}(\.{"Missing\ font\ identifier"})$;\5
$\\{help2}(\.{"I\ was\ looking\ for\ a\ control\ sequence\ whose"})$\6
$(\.{"current\ meaning\ has\ been\ defined\ by\ \\font."})$;\5
\\{back\_error};\5
$\|f\K\\{null\_font}$;\6
\&{end};\2\2\2\6
$\\{cur\_val}\K\|f$;\6
\&{end};\par
\A section~578.
\U section~409.\fi

\M578. The following routine is used to implement `\.{\\fontdimen} \|n \|f'.
The boolean parameter \\{writing} is set \\{true} if the calling program
intends to change the parameter value.

\Y\P$\4\X577:Declare procedures that scan font-related stuff\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{find\_font\_dimen}(\\{writing}:\\{boolean})$;\C{sets
\\{cur\_val} to \\{font\_info} location}\6
\4\&{var} \37\|f: \37\\{internal\_font\_number};\5
\|n: \37\\{integer};\C{the parameter number}\2\6
\&{begin} \37\\{scan\_int};\5
$\|n\K\\{cur\_val}$;\5
\\{scan\_font\_ident};\5
$\|f\K\\{cur\_val}$;\6
\&{if} $\|n\L0$ \1\&{then}\5
$\\{cur\_val}\K\\{fmem\_ptr}$\6
\4\&{else} \&{begin} \37\&{if} $\\{writing}\W(\|n\L\\{space\_shrink\_code})\W%
\30(\|n\G\\{space\_code})\W(\\{font\_glue}[\|f]\I\\{null})$ \1\&{then}\6
\&{begin} \37$\\{delete\_glue\_ref}(\\{font\_glue}[\|f])$;\5
$\\{font\_glue}[\|f]\K\\{null}$;\6
\&{end};\2\6
\&{if} $\|n>\\{font\_params}[\|f]$ \1\&{then}\6
\&{if} $\|f<\\{font\_ptr}$ \1\&{then}\5
$\\{cur\_val}\K\\{fmem\_ptr}$\6
\4\&{else} \X580:Increase the number of parameters in the last font\X\2\6
\4\&{else} $\\{cur\_val}\K\|n+\\{param\_base}[\|f]$;\2\6
\&{end};\2\6
\X579:Issue an error message if $\\{cur\_val}=\\{fmem\_ptr}$\X;\6
\&{end};\par
\fi

\M579. \P$\X579:Issue an error message if $\\{cur\_val}=\\{fmem\_ptr}$\X\S$\6
\&{if} $\\{cur\_val}=\\{fmem\_ptr}$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Font\ "})$;\5
$\\{print\_esc}(\\{font\_id\_text}(\|f))$;\5
$\\{print}(\.{"\ has\ only\ "})$;\5
$\\{print\_int}(\\{font\_params}[\|f])$;\5
$\\{print}(\.{"\ fontdimen\ parameters"})$;\5
$\\{help2}(\.{"To\ increase\ the\ number\ of\ font\ parameters,\ you\ must"})$\6
$(\.{"use\ \\fontdimen\ immediately\ after\ the\ \\font\ is\ loaded."})$;\5
\\{error};\6
\&{end}\2\par
\U section~578.\fi

\M580. \P$\X580:Increase the number of parameters in the last font\X\S$\6
\&{begin} \37\1\&{repeat} \37\&{if} $\\{fmem\_ptr}=\\{font\_mem\_size}$ \1%
\&{then}\5
$\\{overflow}(\.{"font\ memory"},\39\\{font\_mem\_size})$;\2\6
$\\{font\_info}[\\{fmem\_ptr}].\\{sc}\K0$;\5
$\\{incr}(\\{fmem\_ptr})$;\5
$\\{incr}(\\{font\_params}[\|f])$;\6
\4\&{until}\5
$\|n=\\{font\_params}[\|f]$;\2\6
$\\{cur\_val}\K\\{fmem\_ptr}-1$;\C{this equals $\\{param\_base}[\|f]+\\{font%
\_params}[\|f]$}\6
\&{end}\par
\U section~578.\fi

\M581. When \TeX\ wants to typeset a character that doesn't exist, the
character node is not created; thus the output routine can assume
that characters exist when it sees them. The following procedure
prints a warning message unless the user has suppressed it.

\Y\P\4\&{procedure}\1\  \37$\\{char\_warning}(\|f:\\{internal\_font\_number};\,%
\35\|c:\\{eight\_bits})$;\2\6
\&{begin} \37\&{if} $\\{tracing\_lost\_chars}>0$ \1\&{then}\6
\&{begin} \37\\{begin\_diagnostic};\5
$\\{print\_nl}(\.{"Missing\ character:\ There\ is\ no\ "})$;\5
$\\{print\_ASCII}(\|c)$;\5
$\\{print}(\.{"\ in\ font\ "})$;\5
$\\{print}(\\{font\_name}[\|f])$;\5
$\\{print\_char}(\.{"!"})$;\5
$\\{end\_diagnostic}(\\{false})$;\6
\&{end};\2\6
\&{end};\par
\fi

\M582\*. Here is a function that returns a pointer to a character node for a
given character in a given font. If that character doesn't exist,
\\{null} is returned instead.

\Y\P\4\&{function}\1\  \37$\\{new\_character}(\|f:\\{internal\_font\_number};\,%
\35\|c:\\{eight\_bits})$: \37\\{pointer};\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37\|p: \37\\{pointer};\C{newly allocated node}\2\6
\&{begin} \37\&{if} $\\{font\_bc}[\|f]\L\|c$ \1\&{then}\6
\&{if} $\\{font\_ec}[\|f]\G\|c$ \1\&{then}\6
\&{if} $\\{char\_exists}(\\{char\_info}(\|f)(\\{qi}(\|c)))$ \1\&{then}\6
\&{begin} \37$\|p\K\\{get\_avail}$;\5
$\\{font}(\|p)\K\|f$;\5
$\\{character}(\|p)\K\\{qi}(\|c)$;\5
$\\{new\_character}\K\|p$;\5
\&{return};\6
\&{end};\2\2\2\6
$\\{char\_warning}(\|f,\39\|c)$;\5
$\\{new\_character}\K\\{null}$;\6
\4\\{exit}: \37\&{end};\7
\4\&{function}\1\  \37$\\{new\_xchar}(\|f:\\{internal\_font\_number};\,\35\|c:%
\\{integer})$: \37\\{pointer};\6
\4\&{var} \37$\|p,\39\|q$: \37\\{pointer};\C{newly allocated nodes}\2\6
\&{begin} \37$\|q\K\\{new\_character}(\|f,\39\|c\mathbin{\&{mod}}256)$;\6
\&{if} $\|q=\\{null}$ \1\&{then}\5
$\\{new\_xchar}\K\\{null}$\6
\4\&{else} \&{begin} \37$\|p\K\\{get\_avail}$;\5
$\\{font}(\|p)\K\\{font\_base}$;\5
$\\{character}(\|p)\K\\{qi}((\|c\mathbin{\&{div}}256))$;\5
$\\{link}(\|p)\K\|q$;\5
$\\{new\_xchar}\K\|p$;\6
\&{end};\2\6
\&{end};\par
\fi

\N583.  \[31] Device-independent file format.
The most important output produced by a run of \TeX\ is the ``device
independent'' (\.{DVI}) file that specifies where characters and rules
are to appear on printed pages. The form of these files was designed by
David R. Fuchs in 1979. Almost any reasonable typesetting device can be
driven by a program that takes \.{DVI} files as input, and dozens of such
\.{DVI}-to-whatever programs have been written. Thus, it is possible to
print the output of \TeX\ on many different kinds of equipment, using \TeX\
as a device-independent ``front end.''

A \.{DVI} file is a stream of 8-bit bytes, which may be regarded as a
series of commands in a machine-like language. The first byte of each command
is the operation code, and this code is followed by zero or more bytes
that provide parameters to the command. The parameters themselves may consist
of several consecutive bytes; for example, the `\\{set\_rule}' command has two
parameters, each of which is four bytes long. Parameters are usually
regarded as nonnegative integers; but four-byte-long parameters,
and shorter parameters that denote distances, can be
either positive or negative. Such parameters are given in two's complement
notation. For example, a two-byte-long distance parameter has a value between
$-2↑{15}$ and $2↑{15}-1$. As in \.{TFM} files, numbers that occupy
more than one byte position appear in BigEndian order.

A \.{DVI} file consists of a ``preamble,'' followed by a sequence of one
or more ``pages,'' followed by a ``postamble.'' The preamble is simply a
\\{pre} command, with its parameters that define the dimensions used in the
file; this must come first.  Each ``page'' consists of a \\{bop} command,
followed by any number of other commands that tell where characters are to
be placed on a physical page, followed by an \\{eop} command. The pages
appear in the order that \TeX\ generated them. If we ignore \\{nop} commands
and \\{fnt\_def} commands (which are allowed between any two commands in
the file), each \\{eop} command is immediately followed by a \\{bop} command,
or by a \\{post} command; in the latter case, there are no more pages in the
file, and the remaining bytes form the postamble.  Further details about
the postamble will be explained later.

Some parameters in \.{DVI} commands are ``pointers.'' These are four-byte
quantities that give the location number of some other byte in the file;
the first byte is number~0, then comes number~1, and so on. For example,
one of the parameters of a \\{bop} command points to the previous \\{bop};
this makes it feasible to read the pages in backwards order, in case the
results are being directed to a device that stacks its output face up.
Suppose the preamble of a \.{DVI} file occupies bytes 0 to 99. Now if the
first page occupies bytes 100 to 999, say, and if the second
page occupies bytes 1000 to 1999, then the \\{bop} that starts in byte 1000
points to 100 and the \\{bop} that starts in byte 2000 points to 1000. (The
very first \\{bop}, i.e., the one that starts in byte 100, has a pointer of
$-1$.)

\fi

\M584. The \.{DVI} format is intended to be both compact and easily interpreted
by a machine. Compactness is achieved by making most of the information
implicit instead of explicit. When a \.{DVI}-reading program reads the
commands for a page, it keeps track of several quantities: (a)~The current
font \|f is an integer; this value is changed only
by \\{fnt} and \\{fnt\_num} commands. (b)~The current position on the page
is given by two numbers called the horizontal and vertical coordinates,
\|h and \|v. Both coordinates are zero at the upper left corner of the page;
moving to the right corresponds to increasing the horizontal coordinate, and
moving down corresponds to increasing the vertical coordinate. Thus, the
coordinates are essentially Cartesian, except that vertical directions are
flipped; the Cartesian version of $(\|h,\|v)$ would be $(\|h,-\|v)$.  (c)~The
current spacing amounts are given by four numbers \|w, \|x, \|y, and \|z,
where \|w and~\|x are used for horizontal spacing and where \|y and~\|z
are used for vertical spacing. (d)~There is a stack containing
$(\|h,\|v,\|w,\|x,\|y,\|z)$ values; the \.{DVI} commands \\{push} and \\{pop}
are used to
change the current level of operation. Note that the current font~\|f is
not pushed and popped; the stack contains only information about
positioning.

The values of \|h, \|v, \|w, \|x, \|y, and \|z are signed integers having up
to 32 bits, including the sign. Since they represent physical distances,
there is a small unit of measurement such that increasing \|h by~1 means
moving a certain tiny distance to the right. The actual unit of
measurement is variable, as explained below; \TeX\ sets things up so that
its \.{DVI} output is in sp units, i.e., scaled points, in agreement with
all the \\{scaled} dimensions in \TeX's data structures.

\fi

\M585. Here is a list of all the commands that may appear in a \.{DVI} file.
Each
command is specified by its symbolic name (e.g., \\{bop}), its opcode byte
(e.g., 139), and its parameters (if any). The parameters are followed
by a bracketed number telling how many bytes they occupy; for example,
`$\|p[4]$' means that parameter \|p is four bytes long.

\yskip\hang\\{set\_char\_0} 0. Typeset character number~0 from font~\|f
such that the reference point of the character is at $(\|h,\|v)$. Then
increase \|h by the width of that character. Note that a character may
have zero or negative width, so one cannot be sure that \|h will advance
after this command; but \|h usually does increase.

\yskip\hang\\{set\_char\_1} through \\{set\_char\_127} (opcodes 1 to 127).
Do the operations of \\{set\_char\_0}; but use the character whose number
matches the opcode, instead of character~0.

\yskip\hang\\{set1} 128 $\|c[1]$. Same as \\{set\_char\_0}, except that
character
number~\|c is typeset. \TeX82 uses this command for characters in the
range $128\L\|c<256$.

\yskip\hang\\{set2} 129 $\|c[2]$. Same as \\{set1}, except that \|c~is two
bytes long, so it is in the range $0\L\|c<65536$. \TeX82 never uses this
command, but it should come in handy for extensions of \TeX\ that deal
with oriental languages.

\yskip\hang\\{set3} 130 $\|c[3]$. Same as \\{set1}, except that \|c~is three
bytes long, so it can be as large as $2↑{24}-1$. Not even the Chinese
language has this many characters, but this command might prove useful
in some yet unforeseen extension.

\yskip\hang\\{set4} 131 $\|c[4]$. Same as \\{set1}, except that \|c~is four
bytes long. Imagine that.

\yskip\hang\\{set\_rule} 132 $\|a[4]$ $\|b[4]$. Typeset a solid black rectangle
of height~\|a and width~\|b, with its bottom left corner at $(\|h,\|v)$. Then
set $\|h\K\|h+\|b$. If either $\|a\L0$ or $\|b\L0$, nothing should be typeset.
Note
that if $\|b<0$, the value of \|h will decrease even though nothing else
happens.
See below for details about how to typeset rules so that consistency with
\MF\ is guaranteed.

\yskip\hang\\{put1} 133 $\|c[1]$. Typeset character number~\|c from font~\|f
such that the reference point of the character is at $(\|h,\|v)$. (The `put'
commands are exactly like the `set' commands, except that they simply put out a
character or a rule without moving the reference point afterwards.)

\yskip\hang\\{put2} 134 $\|c[2]$. Same as \\{set2}, except that \|h is not
changed.

\yskip\hang\\{put3} 135 $\|c[3]$. Same as \\{set3}, except that \|h is not
changed.

\yskip\hang\\{put4} 136 $\|c[4]$. Same as \\{set4}, except that \|h is not
changed.

\yskip\hang\\{put\_rule} 137 $\|a[4]$ $\|b[4]$. Same as \\{set\_rule}, except
that
\|h is not changed.

\yskip\hang\\{nop} 138. No operation, do nothing. Any number of \\{nop}'s
may occur between \.{DVI} commands, but a \\{nop} cannot be inserted between
a command and its parameters or between two parameters.

\yskip\hang\\{bop} 139 $c_0[4]$ $c_1[4]$ $\ldots$ $c_9[4]$ $p[4]$. Beginning
of a page: Set $(\|h,\|v,\|w,\|x,\|y,\|z)\K(0,0,0,0,0,0)$ and set the stack
empty. Set
the current font \|f to an undefined value.  The ten $c_i$ parameters hold
the values of \.{\\count0} $\ldots$ \.{\\count9} in \TeX\ at the time
\.{\\shipout} was invoked for this page; they can be used to identify
pages, if a user wants to print only part of a \.{DVI} file. The parameter
\|p points to the previous \\{bop} command in the file, where the first
\\{bop} has $p=-1$.

\yskip\hang\\{eop} 140.  End of page: Print what you have read since the
previous \\{bop}. At this point the stack should be empty. (The \.{DVI}-reading
programs that drive most output devices will have kept a buffer of the
material that appears on the page that has just ended. This material is
largely, but not entirely, in order by \|v coordinate and (for fixed \|v) by
\|h~coordinate; so it usually needs to be sorted into some order that is
appropriate for the device in question.)

\yskip\hang\\{push} 141. Push the current values of $(\|h,\|v,\|w,\|x,\|y,\|z)$
onto the
top of the stack; do not change any of these values. Note that \|f is
not pushed.

\yskip\hang\\{pop} 142. Pop the top six values off of the stack and assign
them respectively to $(\|h,\|v,\|w,\|x,\|y,\|z)$. The number of pops should
never
exceed the number of pushes, since it would be highly embarrassing if the
stack were empty at the time of a \\{pop} command.

\yskip\hang\\{right1} 143 $\|b[1]$. Set $\|h\K\|h+\|b$, i.e., move right \|b
units.
The parameter is a signed number in two's complement notation, $-128\L\|b<128$;
if $\|b<0$, the reference point actually moves left.

\yskip\hang\\{right2} 144 $\|b[2]$. Same as \\{right1}, except that \|b is a
two-byte quantity in the range $-32768\L\|b<32768$.

\yskip\hang\\{right3} 145 $\|b[3]$. Same as \\{right1}, except that \|b is a
three-byte quantity in the range $\hbox{$-2↑{23}$}\L\|b<\hbox{$2↑{23}$}$.

\yskip\hang\\{right4} 146 $\|b[4]$. Same as \\{right1}, except that \|b is a
four-byte quantity in the range $\hbox{$-2↑{31}$}\L\|b<\hbox{$2↑{31}$}$.

\yskip\hang\\{w0} 147. Set $\|h\K\|h+\|w$; i.e., move right \|w units. With
luck,
this parameterless command will usually suffice, because the same kind of
motion
will occur several times in succession; the following commands explain how
\|w gets particular values.

\yskip\hang\\{w1} 148 $\|b[1]$. Set $\|w\K\|b$ and $\|h\K\|h+\|b$. The value of
\|b is a
signed quantity in two's complement notation, $-128\L\|b<128$. This command
changes the current \|w~spacing and moves right by \|b.

\yskip\hang\\{w2} 149 $\|b[2]$. Same as \\{w1}, but \|b is two bytes long,
$-32768\L\|b<32768$.

\yskip\hang\\{w3} 150 $\|b[3]$. Same as \\{w1}, but \|b is three bytes long,
$\hbox{$-2↑{23}$}\L\|b<\hbox{$2↑{23}$}$.

\yskip\hang\\{w4} 151 $\|b[4]$. Same as \\{w1}, but \|b is four bytes long,
$\hbox{$-2↑{31}$}\L\|b<\hbox{$2↑{31}$}$.

\yskip\hang\\{x0} 152. Set $\|h\K\|h+\|x$; i.e., move right \|x units. The `%
\|x'
commands are like the `\|w' commands except that they involve \|x instead
of \|w.

\yskip\hang\\{x1} 153 $\|b[1]$. Set $\|x\K\|b$ and $\|h\K\|h+\|b$. The value of
\|b is a
signed quantity in two's complement notation, $-128\L\|b<128$. This command
changes the current \|x~spacing and moves right by \|b.

\yskip\hang\\{x2} 154 $\|b[2]$. Same as \\{x1}, but \|b is two bytes long,
$-32768\L\|b<32768$.

\yskip\hang\\{x3} 155 $\|b[3]$. Same as \\{x1}, but \|b is three bytes long,
$\hbox{$-2↑{23}$}\L\|b<\hbox{$2↑{23}$}$.

\yskip\hang\\{x4} 156 $\|b[4]$. Same as \\{x1}, but \|b is four bytes long,
$\hbox{$-2↑{31}$}\L\|b<\hbox{$2↑{31}$}$.

\yskip\hang\\{down1} 157 $\|a[1]$. Set $\|v\K\|v+\|a$, i.e., move down \|a
units.
The parameter is a signed number in two's complement notation, $-128\L\|a<128$;
if $\|a<0$, the reference point actually moves up.

\yskip\hang\\{down2} 158 $\|a[2]$. Same as \\{down1}, except that \|a is a
two-byte quantity in the range $-32768\L\|a<32768$.

\yskip\hang\\{down3} 159 $\|a[3]$. Same as \\{down1}, except that \|a is a
three-byte quantity in the range $\hbox{$-2↑{23}$}\L\|a<\hbox{$2↑{23}$}$.

\yskip\hang\\{down4} 160 $\|a[4]$. Same as \\{down1}, except that \|a is a
four-byte quantity in the range $\hbox{$-2↑{31}$}\L\|a<\hbox{$2↑{31}$}$.

\yskip\hang\\{y0} 161. Set $\|v\K\|v+\|y$; i.e., move down \|y units. With
luck,
this parameterless command will usually suffice, because the same kind of
motion
will occur several times in succession; the following commands explain how
\|y gets particular values.

\yskip\hang\\{y1} 162 $\|a[1]$. Set $\|y\K\|a$ and $\|v\K\|v+\|a$. The value of
\|a is a
signed quantity in two's complement notation, $-128\L\|a<128$. This command
changes the current \|y~spacing and moves down by \|a.

\yskip\hang\\{y2} 163 $\|a[2]$. Same as \\{y1}, but \|a is two bytes long,
$-32768\L\|a<32768$.

\yskip\hang\\{y3} 164 $\|a[3]$. Same as \\{y1}, but \|a is three bytes long,
$\hbox{$-2↑{23}$}\L\|a<\hbox{$2↑{23}$}$.

\yskip\hang\\{y4} 165 $\|a[4]$. Same as \\{y1}, but \|a is four bytes long,
$\hbox{$-2↑{31}$}\L\|a<\hbox{$2↑{31}$}$.

\yskip\hang\\{z0} 166. Set $\|v\K\|v+\|z$; i.e., move down \|z units. The `\|z'
commands
are like the `\|y' commands except that they involve \|z instead of \|y.

\yskip\hang\\{z1} 167 $\|a[1]$. Set $\|z\K\|a$ and $\|v\K\|v+\|a$. The value of
\|a is a
signed quantity in two's complement notation, $-128\L\|a<128$. This command
changes the current \|z~spacing and moves down by \|a.

\yskip\hang\\{z2} 168 $\|a[2]$. Same as \\{z1}, but \|a is two bytes long,
$-32768\L\|a<32768$.

\yskip\hang\\{z3} 169 $\|a[3]$. Same as \\{z1}, but \|a is three bytes long,
$\hbox{$-2↑{23}$}\L\|a<\hbox{$2↑{23}$}$.

\yskip\hang\\{z4} 170 $\|a[4]$. Same as \\{z1}, but \|a is four bytes long,
$\hbox{$-2↑{31}$}\L\|a<\hbox{$2↑{31}$}$.

\yskip\hang\\{fnt\_num\_0} 171. Set $\|f\K0$. Font 0 must previously have been
defined by a \\{fnt\_def} instruction, as explained below.

\yskip\hang\\{fnt\_num\_1} through \\{fnt\_num\_63} (opcodes 172 to 234). Set
$\|f\K1$, \dots, \hbox{$\|f\K63$}, respectively.

\yskip\hang\\{fnt1} 235 $\|k[1]$. Set $\|f\K\|k$. \TeX82 uses this command for
font
numbers in the range $64\L\|k<256$.

\yskip\hang\\{fnt2} 236 $\|k[2]$. Same as \\{fnt1}, except that \|k~is two
bytes long, so it is in the range $0\L\|k<65536$. \TeX82 never generates this
command, but large font numbers may prove useful for specifications of
color or texture, or they may be used for special fonts that have fixed
numbers in some external coding scheme.

\yskip\hang\\{fnt3} 237 $\|k[3]$. Same as \\{fnt1}, except that \|k~is three
bytes long, so it can be as large as $2↑{24}-1$.

\yskip\hang\\{fnt4} 238 $\|k[4]$. Same as \\{fnt1}, except that \|k~is four
bytes long; this is for the really big font numbers (and for the negative
ones).

\yskip\hang\\{xxx1} 239 $\|k[1]$ $\|x[\|k]$. This command is undefined in
general; it functions as a $(k+2)$-byte \\{nop} unless special \.{DVI}-reading
programs are being used. \TeX82 generates \\{xxx1} when a short enough
\.{\\special} appears, setting \|k to the number of bytes being sent. It
is recommended that \|x be a string having the form of a keyword followed
by possible parameters relevant to that keyword.

\yskip\hang\\{xxx2} 240 $\|k[2]$ $\|x[\|k]$. Like \\{xxx1}, but $0\L\|k<65536$.

\yskip\hang\\{xxx3} 241 $\|k[3]$ $\|x[\|k]$. Like \\{xxx1}, but $0\L\|k<%
\hbox{$2↑{24}$}$.

\yskip\hang\\{xxx4} 242 $\|k[4]$ $\|x[\|k]$. Like \\{xxx1}, but \|k can be
ridiculously
large. \TeX82 uses \\{xxx4} when sending a string of length 256 or more.

\yskip\hang\\{fnt\_def1} 243 $\|k[1]$ $\|c[4]$ $\|s[4]$ $\|d[4]$ $\|a[1]$ $%
\|l[1]$ $\|n[\|a+\|l]$.
Define font \|k, where $0\L\|k<256$; font definitions will be explained
shortly.

\yskip\hang\\{fnt\_def2} 244 $\|k[2]$ $\|c[4]$ $\|s[4]$ $\|d[4]$ $\|a[1]$ $%
\|l[1]$ $\|n[\|a+\|l]$.
Define font \|k, where $0\L\|k<65536$.

\yskip\hang\\{fnt\_def3} 245 $\|k[3]$ $\|c[4]$ $\|s[4]$ $\|d[4]$ $\|a[1]$ $%
\|l[1]$ $\|n[\|a+\|l]$.
Define font \|k, where $0\L\|k<\hbox{$2↑{24}$}$.

\yskip\hang\\{fnt\_def4} 246 $\|k[4]$ $\|c[4]$ $\|s[4]$ $\|d[4]$ $\|a[1]$ $%
\|l[1]$ $\|n[\|a+\|l]$.
Define font \|k, where $\hbox{$-2↑{31}$}\L\|k<\hbox{$2↑{31}$}$.

\yskip\hang\\{pre} 247 $\|i[1]$ $\\{num}[4]$ $\\{den}[4]$ $\\{mag}[4]$ $\|k[1]$
$\|x[\|k]$.
Beginning of the preamble; this must come at the very beginning of the
file. Parameters \|i, \\{num}, \\{den}, \\{mag}, \|k, and \|x are explained
below.

\yskip\hang\\{post} 248. Beginning of the postamble, see below.

\yskip\hang\\{post\_post} 249. Ending of the postamble, see below.

\yskip\noindent Commands 250--255 are undefined at the present time.

\fi

\M586. \P\D \37$\\{set\_char\_0}=0$\C{typeset character 0 and move right}\par
\P\D \37$\\{set1}=128$\C{typeset a character and move right}\par
\P\D \37$\\{set\_rule}=132$\C{typeset a rule and move right}\par
\P\D \37$\\{put1}=133$\C{typeset a character}\par
\P\D \37$\\{put\_rule}=137$\C{typeset a rule}\par
\P\D \37$\\{nop}=138$\C{no operation}\par
\P\D \37$\\{bop}=139$\C{beginning of page}\par
\P\D \37$\\{eop}=140$\C{ending of page}\par
\P\D \37$\\{push}=141$\C{save the current positions}\par
\P\D \37$\\{pop}=142$\C{restore previous positions}\par
\P\D \37$\\{right1}=143$\C{move right}\par
\P\D \37$\\{w0}=147$\C{move right by \|w}\par
\P\D \37$\\{w1}=148$\C{move right and set \|w}\par
\P\D \37$\\{x0}=152$\C{move right by \|x}\par
\P\D \37$\\{x1}=153$\C{move right and set \|x}\par
\P\D \37$\\{down1}=157$\C{move down}\par
\P\D \37$\\{y0}=161$\C{move down by \|y}\par
\P\D \37$\\{y1}=162$\C{move down and set \|y}\par
\P\D \37$\\{z0}=166$\C{move down by \|z}\par
\P\D \37$\\{z1}=167$\C{move down and set \|z}\par
\P\D \37$\\{fnt\_num\_0}=171$\C{set current font to 0}\par
\P\D \37$\\{fnt1}=235$\C{set current font}\par
\P\D \37$\\{xxx1}=239$\C{extension to \.{DVI} primitives}\par
\P\D \37$\\{xxx4}=242$\C{potentially long extension to \.{DVI} primitives}\par
\P\D \37$\\{fnt\_def1}=243$\C{define the meaning of a font number}\par
\P\D \37$\\{pre}=247$\C{preamble}\par
\P\D \37$\\{post}=248$\C{postamble beginning}\par
\P\D \37$\\{post\_post}=249$\C{postamble ending}\par
\fi

\M587. The preamble contains basic information about the file as a whole. As
stated above, there are six parameters:
$$\hbox{$\|i[1]$ $\\{num}[4]$ $\\{den}[4]$ $\\{mag}[4]$ $\|k[1]$ $\|x[\|k]$.}$$
The \|i byte identifies \.{DVI} format; currently this byte is always set
to~2. (Some day we will set $\|i=3$, when \.{DVI} format makes another
incompatible change---perhaps in 1992.)

The next two parameters, \\{num} and \\{den}, are positive integers that define
the units of measurement; they are the numerator and denominator of a
fraction by which all dimensions in the \.{DVI} file could be multiplied
in order to get lengths in units of $10↑{-7}$ meters. Since $\rm 7227{pt} =
254{cm}$, and since \TeX\ works with scaled points where there are $2↑{16}$
sp in a point, \TeX\ sets
$\\{num}/\\{den}=(254\cdot10↑5)/(7227\cdot2↑{16})=25400000/473628672$.

The \\{mag} parameter is what \TeX\ calls \.{\\mag}, i.e., 1000 times the
desired magnification. The actual fraction by which dimensions are
multiplied is therefore $\\{mag}\cdot\\{num}/1000\\{den}$. Note that if a \TeX\
source document does not call for any `\.{true}' dimensions, and if you
change it only by specifying a different \.{\\mag} setting, the \.{DVI}
file that \TeX\ creates will be completely unchanged except for the value
of \\{mag} in the preamble and postamble. (Fancy \.{DVI}-reading programs allow
users to override the \\{mag}~setting when a \.{DVI} file is being printed.)

Finally, \|k and \|x allow the \.{DVI} writer to include a comment, which is
not
interpreted further. The length of comment \|x is \|k, where $0\L\|k<256$.

\Y\P\D \37$\\{id\_byte}=2$\C{identifies the kind of \.{DVI} files described
here}\par
\fi

\M588. Font definitions for a given font number \|k contain further parameters
$$\hbox{$\|c[4]$ $\|s[4]$ $\|d[4]$ $\|a[1]$ $\|l[1]$ $\|n[\|a+\|l]$.}$$
The four-byte value \|c is the check sum that \TeX\ found in the \.{TFM}
file for this font; \|c should match the check sum of the font found by
programs that read this \.{DVI} file.

Parameter \|s contains a fixed-point scale factor that is applied to the
character widths in font \|k; font dimensions in \.{TFM} files and other
font files are relative to this quantity, which is called the ``at size''
elsewhere in this documentation. The value of \|s is always positive and
less than $2↑{27}$. It is given in the same units as the other \.{DVI}
dimensions, i.e., in sp when \TeX82 has made the file.  Parameter \|d is
similar to \|s; it is the ``design size,'' and it is given in \.{DVI}
units that have not been corrected for the magnification~\\{mag} found in the
preamble.  Thus, font \|k is to be used at $\\{mag}\cdot s/1000d$ times its
normal size.

The remaining part of a font definition gives the external name of the font,
which is an ASCII string of length $\|a+\|l$. The number \|a is the length
of the ``area'' or directory, and \|l is the length of the font name itself;
the standard local system font area is supposed to be used when $\|a=0$.
The \|n field contains the area in its first \|a bytes.

Font definitions must appear before the first use of a particular font number.
Once font \|k is defined, it must not be defined again; however, we
shall see below that font definitions appear in the postamble as well as
in the pages, so in this sense each font number is defined exactly twice,
if at all. Like \\{nop} commands and \\{xxx} commands, font definitions can
appear before the first \\{bop}, or between an \\{eop} and a \\{bop}.

\fi

\M589. Sometimes it is desirable to make horizontal or vertical rules line up
precisely with certain features in characters of a font. It is possible to
guarantee the correct matching between \.{DVI} output and the characters
generated by \MF\ by adhering to the following principles: (1)~The \MF\
characters should be positioned so that a bottom edge or left edge that is
supposed to line up with the bottom or left edge of a rule appears at the
reference point, i.e., in row~0 and column~0 of the \MF\ raster. This
ensures that the position of the rule will not be rounded differently when
the pixel size is not a perfect multiple of the units of measurement in
the \.{DVI} file. (2)~A typeset rule of height $a>0$ and width $b>0$
should be equivalent to a \MF-generated character having black pixels in
precisely those raster positions whose \MF\ coordinates satisfy
$0\L\|x<\hbox{$\alpha$}\|b$ and $0\L\|y<\hbox{$\alpha$}\|a$, where $\alpha$ is
the number
of pixels per \.{DVI} unit.

\fi

\M590. The last page in a \.{DVI} file is followed by `\\{post}'; this command
introduces the postamble, which summarizes important facts that \TeX\ has
accumulated about the file, making it possible to print subsets of the data
with reasonable efficiency. The postamble has the form
$$\vbox{\halign{\hbox{#\hfil}\cr
\\{post} $\|p[4]$ $\\{num}[4]$ $\\{den}[4]$ $\\{mag}[4]$ $\|l[4]$ $\|u[4]$ $%
\|s[2]$ $\|t[2]$\cr
$\langle\,$font definitions$\,\rangle$\cr
\\{post\_post} $\|q[4]$ $\|i[1]$ 223's$[{\G}4]$\cr}}$$
Here \|p is a pointer to the final \\{bop} in the file. The next three
parameters, \\{num}, \\{den}, and \\{mag}, are duplicates of the quantities
that
appeared in the preamble.

Parameters \|l and \|u give respectively the height-plus-depth of the tallest
page and the width of the widest page, in the same units as other dimensions
of the file. These numbers might be used by a \.{DVI}-reading program to
position individual ``pages'' on large sheets of film or paper; however,
the standard convention for output on normal size paper is to position each
page so that the upper left-hand corner is exactly one inch from the left
and the top. Experience has shown that it is unwise to design %
\.{DVI}-to-printer
software that attempts cleverly to center the output; a fixed position of
the upper left corner is easiest for users to understand and to work with.
Therefore \|l and~\|u are often ignored.

Parameter \|s is the maximum stack depth (i.e., the largest excess of
\\{push} commands over \\{pop} commands) needed to process this file. Then
comes \|t, the total number of pages (\\{bop} commands) present.

The postamble continues with font definitions, which are any number of
\\{fnt\_def} commands as described above, possibly interspersed with \\{nop}
commands. Each font number that is used in the \.{DVI} file must be defined
exactly twice: Once before it is first selected by a \\{fnt} command, and once
in the postamble.

\fi

\M591. The last part of the postamble, following the \\{post\_post} byte that
signifies the end of the font definitions, contains \|q, a pointer to the
\\{post} command that started the postamble.  An identification byte, \|i,
comes next; this currently equals~2, as in the preamble.

The \|i byte is followed by four or more bytes that are all equal to
the decimal number 223 (i.e., \O{337} in octal). \TeX\ puts out four to seven
of
these trailing bytes, until the total length of the file is a multiple of
four bytes, since this works out best on machines that pack four bytes per
word; but any number of 223's is allowed, as long as there are at least four
of them. In effect, 223 is a sort of signature that is added at the very end.

This curious way to finish off a \.{DVI} file makes it feasible for
\.{DVI}-reading programs to find the postamble first, on most computers,
even though \TeX\ wants to write the postamble last. Most operating
systems permit random access to individual words or bytes of a file, so
the \.{DVI} reader can start at the end and skip backwards over the 223's
until finding the identification byte. Then it can back up four bytes, read
\|q, and move to byte \|q of the file. This byte should, of course,
contain the value 248 (\\{post}); now the postamble can be read, so the
\.{DVI} reader can discover all the information needed for typesetting the
pages. Note that it is also possible to skip through the \.{DVI} file at
reasonably high speed to locate a particular page, if that proves
desirable. This saves a lot of time, since \.{DVI} files used in production
jobs tend to be large.

Unfortunately, however, standard \PASCAL\ does not include the ability to
access a random position in a file, or even to determine the length of a file.
Almost all systems nowadays provide the necessary capabilities, so \.{DVI}
format has been designed to work most efficiently with modern operating
systems.
But if \.{DVI} files have to be processed under the restrictions of standard
\PASCAL, one can simply read them from front to back, since the necessary
header information is present in the preamble and in the font definitions.
(The \|l and \|u and \|s and \|t parameters, which appear only in the
postamble, are ``frills'' that are handy but not absolutely necessary.)
\fi

\N592.  \[32] Shipping pages out.
After considering \TeX's eyes and stomach, we come now to the bowels.

The \\{ship\_out} procedure is given a pointer to a box; its mission is
to describe that box in \.{DVI} form, outputting a ``page'' to \\{dvi\_file}.
The \.{DVI} coordinates $(h,v)=(0,0)$ should correspond to the upper left
corner of the box being shipped.

Since boxes can be inside of boxes inside of boxes, the main work of
\\{ship\_out} is done by two mutually recursive routines, \\{hlist\_out}
and \\{vlist\_out}, which traverse the hlists and vlists inside of horizontal
and vertical boxes.

As individual pages are being processed, we need to accumulate
information about the entire set of pages, since such statistics must be
reported in the postamble. The global variables \\{total\_pages}, \\{max\_v},
\\{max\_h}, \\{max\_push}, and \\{last\_bop} are used to record this
information.

The variable \\{doing\_leaders} is \\{true} while leaders are being output.
The variable \\{dead\_cycles} contains the number of times an output routine
has been initiated since the last \\{ship\_out}.

A few additional global variables are also defined here for use in
\\{vlist\_out} and \\{hlist\_out}. They could have been local variables, but
that would waste stack space when boxes are deeply nested, since the
values of these variables are not needed during recursive calls.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{total\_pages}: \37\\{integer};\C{the number of pages that have been
shipped out}\6
\4\\{max\_v}: \37\\{scaled};\C{maximum height-plus-depth of pages shipped so
far}\6
\4\\{max\_h}: \37\\{scaled};\C{maximum width of pages shipped so far}\6
\4\\{max\_push}: \37\\{integer};\C{deepest nesting of \\{push} commands
encountered so far}\6
\4\\{last\_bop}: \37\\{integer};\C{location of previous \\{bop} in the \.{DVI}
output}\6
\4\\{dead\_cycles}: \37\\{integer};\C{recent outputs that didn't ship anything
out}\6
\4\\{doing\_leaders}: \37\\{boolean};\C{are we inside a leader box?}\7
\4$\|c,\39\|f$: \37\\{quarterword};\C{character and font in current \\{char%
\_node}}\6
\4$\\{rule\_ht},\39\\{rule\_dp},\39\\{rule\_wd}$: \37\\{scaled};\C{size of
current rule being output}\6
\4\|g: \37\\{pointer};\C{current glue specification}\6
\4$\\{lq},\39\\{lr}$: \37\\{integer};\C{quantities used in calculations for
leaders}\par
\fi

\M593. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{total\_pages}\K0$;\5
$\\{max\_v}\K0$;\5
$\\{max\_h}\K0$;\5
$\\{max\_push}\K0$;\5
$\\{last\_bop}\K-1$;\5
$\\{doing\_leaders}\K\\{false}$;\5
$\\{dead\_cycles}\K0$;\par
\fi

\M594\*. The \.{DVI} bytes are output to a buffer instead of being written
directly
to the output file. This makes it possible to reduce the overhead of
subroutine calls, thereby measurably speeding up the computation, since
output of \.{DVI} bytes is part of \TeX's inner loop. And it has another
advantage as well, since we can change instructions in the buffer in order to
make the output more compact. For example, a `\\{down2}' command can be
changed to a `\\{y2}', thereby making a subsequent `\\{y0}' command possible,
saving two bytes.

The output buffer is divided into two parts of equal size; the bytes found
in $\\{dvi\_buf}[0\to\\{half\_buf}-1]$ constitute the first half, and those in
$\\{dvi\_buf}[\\{half\_buf}\to\\{dvi\_buf\_size}-1]$ constitute the second. The
global
variable \\{dvi\_ptr} points to the position that will receive the next
output byte. When \\{dvi\_ptr} reaches \\{dvi\_limit}, which is always equal
to one of the two values \\{half\_buf} or \\{dvi\_buf\_size}, the half buffer
that
is about to be invaded next is sent to the output and \\{dvi\_limit} is
changed to its other value. Thus, there is always at least a half buffer's
worth of information present, except at the very beginning of the job.

Bytes of the \.{DVI} file are numbered sequentially starting with 0;
the next byte to be generated will be number $\\{dvi\_offset}+\\{dvi\_ptr}$.
A byte is present in the buffer only if its number is $\G\\{dvi\_gone}$.

\Y\P$\4\X18:Types in the outer block\X\mathrel{+}\S$\6
$\\{dvi\_index}=0\to\\{dvi\_buf\_size}$;\C{an index into the output buffer}\6
$\\{packed\_bytes}=$\1\5
\&{packed} \37\&{array} $[\\{dvi\_index}]$ \1\&{of}\5
\\{eight\_bits};\C{buffer for \.{DVI} output}\2\2\par
\fi

\M595\*. Some systems may find it more efficient to make \\{dvi\_buf} a %
\&{packed}
array, since output of four bytes at once may be facilitated.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{dvi\_buf}: \37\\{packed\_bytes};\C{buffer for \.{DVI} output}\6
\4\\{half\_buf}: \37\\{dvi\_index};\C{half of \\{dvi\_buf\_size}}\6
\4\\{dvi\_limit}: \37\\{dvi\_index};\C{end of the current half buffer}\6
\4\\{dvi\_ptr}: \37\\{dvi\_index};\C{the next available buffer address}\6
\4\\{dvi\_offset}: \37\\{integer};\C{\\{dvi\_buf\_size} times the number of
times the 	output buffer has been fully emptied}\6
\4\\{dvi\_gone}: \37\\{integer};\C{the number of bytes already output to \\{dvi%
\_file}}\par
\fi

\M596. Initially the buffer is all in one piece; we will output half of it only
after it first fills up.

\Y\P$\4\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{half\_buf}\K\\{dvi\_buf\_size}\mathbin{\&{div}}2$;\5
$\\{dvi\_limit}\K\\{dvi\_buf\_size}$;\5
$\\{dvi\_ptr}\K0$;\5
$\\{dvi\_offset}\K0$;\5
$\\{dvi\_gone}\K0$;\par
\fi

\M597\*. The actual output of $\\{dvi\_buf}[\|a\to\|b]$ to \\{dvi\_file} is
performed by calling
$\\{write\_dvi}(\|a,\|b)$. For best results, this procedure should be optimized
to
run as fast as possible on each particular system, since it is part of
\TeX's inner loop. It is safe to assume that \|a and $\|b+1$ will both be
multiples of 4 when $\\{write\_dvi}(\|a,\|b)$ is called; therefore it is
possible on
many machines to use efficient methods to pack four bytes per word and to
output an array of words with one system call.

\Y\P\4\&{procedure} \1\  \\{ary\_out} ( $\mathop{\&{var}}\|f:$ \&{file} ;\6
\4\|b: \37\\{packed\_bytes};\6
\4$\|o,\39\|c$: \37\\{integer} ) ;\5
\\{extern};\5
\hbox{\2}\7
\4\&{procedure}\1\  \37$\\{write\_dvi}(\|a,\39\|b:\\{dvi\_index})$;\2\6
\&{begin} \37$\\{ary\_out}(\\{dvi\_file},\39\\{dvi\_buf},\39\|a\mathbin{%
\&{div}}4,\39(\|b+1-\|a)\mathbin{\&{div}}4)$;\6
\&{end};\par
\fi

\M598. To put a byte in the buffer without paying the cost of invoking a
procedure
each time, we use the macro \\{dvi\_out}.

\Y\P\D \37$\\{dvi\_out}(\#)\S$\ \&{begin} \37$\\{dvi\_buf}[\\{dvi\_ptr}]\K\#$;\5
$\\{incr}(\\{dvi\_ptr})$;\6
\&{if} $\\{dvi\_ptr}=\\{dvi\_limit}$ \1\&{then}\5
\\{dvi\_swap};\2\6
\&{end}\par
\Y\P\4\&{procedure}\1\  \37\\{dvi\_swap};\C{outputs half of the buffer}\2\6
\&{begin} \37\&{if} $\\{dvi\_limit}=\\{dvi\_buf\_size}$ \1\&{then}\6
\&{begin} \37$\\{write\_dvi}(0,\39\\{half\_buf}-1)$;\5
$\\{dvi\_limit}\K\\{half\_buf}$;\5
$\\{dvi\_offset}\K\\{dvi\_offset}+\\{dvi\_buf\_size}$;\5
$\\{dvi\_ptr}\K0$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{write\_dvi}(\\{half\_buf},\39\\{dvi\_buf%
\_size}-1)$;\5
$\\{dvi\_limit}\K\\{dvi\_buf\_size}$;\6
\&{end};\2\6
$\\{dvi\_gone}\K\\{dvi\_gone}+\\{half\_buf}$;\6
\&{end};\par
\fi

\M599. Here is how we clean out the buffer when \TeX\ is all through; \\{dvi%
\_ptr}
will be a multiple of~4.

\Y\P$\4\X599:Empty the last bytes out of \\{dvi\_buf}\X\S$\6
\&{if} $\\{dvi\_limit}=\\{half\_buf}$ \1\&{then}\5
$\\{write\_dvi}(\\{half\_buf},\39\\{dvi\_buf\_size}-1)$;\2\6
\&{if} $\\{dvi\_ptr}>0$ \1\&{then}\5
$\\{write\_dvi}(0,\39\\{dvi\_ptr}-1)$\2\par
\U section~642\*.\fi

\M600. The \\{dvi\_four} procedure outputs four bytes in two's complement
notation,
without risking arithmetic overflow.

\Y\P\4\&{procedure}\1\  \37$\\{dvi\_four}(\|x:\\{integer})$;\2\6
\&{begin} \37\&{if} $\|x\G0$ \1\&{then}\5
$\\{dvi\_out}(\|x\mathbin{\&{div}}\O{100000000})$\6
\4\&{else} \&{begin} \37$\|x\K\|x+\O{10000000000}$;\5
$\|x\K\|x+\O{10000000000}$;\5
$\\{dvi\_out}((\|x\mathbin{\&{div}}\O{100000000})+128)$;\6
\&{end};\2\6
$\|x\K\|x\mathbin{\&{mod}}\O{100000000}$;\5
$\\{dvi\_out}(\|x\mathbin{\&{div}}\O{200000})$;\5
$\|x\K\|x\mathbin{\&{mod}}\O{200000}$;\5
$\\{dvi\_out}(\|x\mathbin{\&{div}}\O{400})$;\5
$\\{dvi\_out}(\|x\mathbin{\&{mod}}\O{400})$;\6
\&{end};\par
\fi

\M601. A mild optimization of the output is performed by the \\{dvi\_pop}
routine, which issues a \\{pop} unless it is possible to cancel a
`\\{push} \\{pop}' pair. The parameter to \\{dvi\_pop} is the byte address
following the old \\{push} that matches the new \\{pop}.

\Y\P\4\&{procedure}\1\  \37$\\{dvi\_pop}(\|l:\\{integer})$;\2\6
\&{begin} \37\&{if} $(\|l=\\{dvi\_offset}+\\{dvi\_ptr})\W(\\{dvi\_ptr}>0)$ \1%
\&{then}\5
$\\{decr}(\\{dvi\_ptr})$\6
\4\&{else} $\\{dvi\_out}(\\{pop})$;\2\6
\&{end};\par
\fi

\M602. Here's a procedure that outputs a font definition. Since \TeX82 uses at
most 256 different fonts per job, \\{fnt\_def1} is always used as the command
code.

\Y\P\4\&{procedure}\1\  \37$\\{dvi\_font\_def}(\|f:\\{internal\_font%
\_number})$;\6
\4\&{var} \37\|k: \37\\{pool\_pointer};\C{index into \\{str\_pool}}\2\6
\&{begin} \37$\\{dvi\_out}(\\{fnt\_def1})$;\5
$\\{dvi\_out}(\|f-\\{font\_base}-1)$;\6
$\\{dvi\_out}(\\{qo}(\\{font\_check}[\|f].\\{b0}))$;\5
$\\{dvi\_out}(\\{qo}(\\{font\_check}[\|f].\\{b1}))$;\5
$\\{dvi\_out}(\\{qo}(\\{font\_check}[\|f].\\{b2}))$;\5
$\\{dvi\_out}(\\{qo}(\\{font\_check}[\|f].\\{b3}))$;\6
$\\{dvi\_four}(\\{font\_size}[\|f])$;\5
$\\{dvi\_four}(\\{font\_dsize}[\|f])$;\6
$\\{dvi\_out}(\\{length}(\\{font\_area}[\|f]))$;\5
$\\{dvi\_out}(\\{length}(\\{font\_name}[\|f]))$;\5
\X603:Output the font name whose internal number is \|f\X;\6
\&{end};\par
\fi

\M603. \P$\X603:Output the font name whose internal number is \|f\X\S$\6
\&{for} $\|k\K\\{str\_start}[\\{font\_area}[\|f]]\mathrel{\&{to}}\\{str%
\_start}[\\{font\_area}[\|f]+1]-1$ \1\&{do}\5
$\\{dvi\_out}(\\{str\_pool}[\|k])$;\2\6
\&{for} $\|k\K\\{str\_start}[\\{font\_name}[\|f]]\mathrel{\&{to}}\\{str%
\_start}[\\{font\_name}[\|f]+1]-1$ \1\&{do}\5
$\\{dvi\_out}(\\{str\_pool}[\|k])$\2\par
\U section~602.\fi

\M604. Versions of \TeX\ intended for small computers might well choose to omit
the ideas in the next few parts of this program, since it is not really
necessary to optimize the \.{DVI} code by making use of the \\{w0}, \\{x0},
\\{y0}, and \\{z0} commands. Furthermore, the algorithm that we are about to
describe does not pretend to give an optimum reduction in the length
of the \.{DVI} code; after all, speed is more important than compactness.
But the method is surprisingly effective, and it takes comparatively little
time.

We can best understand the basic idea by first considering a simpler problem
that has the same essential characteristics. Given a sequence of digits,
say $3\,1\,4\,1\,5\,9\,2\,6\,5\,3\,5\,8\,9$, we want to assign subscripts
$d$, $y$, or $z$ to each digit so as to maximize the number of ``$y$-hits''
and ``$z$-hits''; a $y$-hit is an instance of two appearances of the same
digit with the subscript $y$, where no $y$'s intervene between the two
appearances, and a $z$-hit is defined similarly. For example, the sequence
above could be decorated with subscripts as follows:
$$3_z\,1_y\,4_d\,1_y\,5_y\,9_d\,2_d\,6_d\,5_y\,3_z\,5_y\,8_d\,9_d.$$
There are three $y$-hits ($1_y\ldots1_y$ and $5_y\ldots5_y\ldots5_y$) and
one $z$-hit ($3_z\ldots3_z$); there are no $d$-hits, since the two appearances
of $9_d$ have $d$'s between them, but we don't count $d$-hits so it doesn't
matter how many there are. These subscripts are analogous to the \.{DVI}
commands called \\{down}, $y$, and $z$, and the digits are analogous to
different amounts of vertical motion; a $y$-hit or $z$-hit corresponds to
the opportunity to use the one-byte commands \\{y0} or \\{z0} in a \.{DVI}
file.

\TeX's method of assigning subscripts works like this: Append a new digit,
say $\delta$, to the right of the sequence. Now look back through the
sequence until one of the following things happens: (a)~You see
$\delta_y$ or $\delta_z$, and this was the first time you encountered a
$y$ or $z$ subscript, respectively.  Then assign $y$ or $z$ to the new
$\delta$; you have scored a hit. (b)~You see $\delta_d$, and no $y$
subscripts have been encountered so far during this search.  Then change
the previous $\delta_d$ to $\delta_y$ (this corresponds to changing a
command in the output buffer), and assign $y$ to the new $\delta$; it's
another hit.  (c)~You see $\delta_d$, and a $y$ subscript has been seen
but not a $z$.  Change the previous $\delta_d$ to $\delta_z$ and assign
$z$ to the new $\delta$. (d)~You encounter both $y$ and $z$ subscripts
before encountering a suitable $\delta$, or you scan all the way to the
front of the sequence. Assign $d$ to the new $\delta$; this assignment may
be changed later.

The subscripts $3_z\,1_y\,4_d\ldots\,$ in the example above were, in fact,
produced by this procedure, as the reader can verify. (Go ahead and try it.)

\fi

\M605. In order to implement such an idea, \TeX\ maintains a stack of pointers
to the \\{down}, $y$, and $z$ commands that have been generated for the
current page. And there is a similar stack for \\{right}, \|w, and \|x
commands. These stacks are called the down stack and right stack, and their
top elements are maintained in the variables \\{down\_ptr} and \\{right\_ptr}.

Each entry in these stacks contains four fields: The \\{width} field is
the amount of motion down or to the right; the \\{location} field is the
byte number of the \.{DVI} command in question (including the appropriate
\\{dvi\_offset}); the \\{link} field points to the next item below this one
on the stack; and the \\{info} field encodes the options for possible change
in the \.{DVI} command.

\Y\P\D \37$\\{movement\_node\_size}=3$\C{number of words per entry in the down
and right stacks}\par
\P\D \37$\\{location}(\#)\S\\{mem}[\#+2].\\{int}$\C{\.{DVI} byte number for a
movement command}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4$\\{down\_ptr},\39\\{right\_ptr}$: \37\\{pointer};\C{heads of the down and
right stacks}\par
\fi

\M606. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{down\_ptr}\K\\{null}$;\5
$\\{right\_ptr}\K\\{null}$;\par
\fi

\M607. Here is a subroutine that produces a \.{DVI} command for some specified
downward or rightward motion. It has two parameters: \|w is the amount
of motion, and \|o is either \\{down1} or \\{right1}. We use the fact that
the command codes have convenient arithmetic properties: $\\{y1}-\\{down1}=%
\\{w1}-\\{right1}$
and $\\{z1}-\\{down1}=\\{x1}-\\{right1}$.

\Y\P\4\&{procedure}\1\  \37$\\{movement}(\|w:\\{scaled};\,\35\|o:\\{eight%
\_bits})$;\6
\4\&{label} \37$\\{exit},\39\\{found},\39\\{not\_found},\392,\391$;\6
\4\&{var} \37\\{mstate}: \37\\{small\_number};\C{have we seen a \|y or \|z?}\6
$\|p,\39\|q$: \37\\{pointer};\C{current and top nodes on the stack}\6
\|k: \37\\{integer};\C{index into \\{dvi\_buf}, modulo \\{dvi\_buf\_size}}\2\6
\&{begin} \37$\|q\K\\{get\_node}(\\{movement\_node\_size})$;\C{new node for the
top of the stack}\6
$\\{width}(\|q)\K\|w$;\5
$\\{location}(\|q)\K\\{dvi\_offset}+\\{dvi\_ptr}$;\6
\&{if} $\|o=\\{down1}$ \1\&{then}\6
\&{begin} \37$\\{link}(\|q)\K\\{down\_ptr}$;\5
$\\{down\_ptr}\K\|q$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{link}(\|q)\K\\{right\_ptr}$;\5
$\\{right\_ptr}\K\|q$;\6
\&{end};\2\6
\X611:Look at the other stack entries until deciding what sort of \.{DVI}
command to generate; \&{goto} \\{found} if node \|p is a ``hit''\X;\6
\X610:Generate a \\{down} or \\{right} command for \|w and \&{return}\X;\6
\4\\{found}: \37\X609:Generate a \\{y0} or \\{z0} command in order to reuse a
previous appearance of~\|w\X;\6
\4\\{exit}: \37\&{end};\par
\fi

\M608. The \\{info} fields in the entries of the down stack or the right stack
have six possible settings: \\{y\_here} or \\{z\_here} mean that the \.{DVI}
command refers to \|y or \|z, respectively (or to \|w or \|x, in the
case of horizontal motion); \\{yz\_OK} means that the \.{DVI} command is
\\{down} (or \\{right}) but can be changed to either \|y or \|z (or
to either \|w or \|x); \\{y\_OK} means that it is \\{down} and can be changed
to \|y but not \|z; \\{z\_OK} is similar; and \\{d\_fixed} means it must stay
\\{down}.

The four settings \\{yz\_OK}, \\{y\_OK}, \\{z\_OK}, \\{d\_fixed} would not need
to
be distinguished from each other if we were simply solving the
digit-subscripting problem mentioned above. But in \TeX's case there is
a complication because of the nested structure of \\{push} and \\{pop}
commands. Suppose we add parentheses to the digit-subscripting problem,
redefining hits so that $\delta_y\ldots \delta_y$ is a hit if all $y$'s between
the $\delta$'s are enclosed in properly nested parentheses, and if the
parenthesis level of the right-hand $\delta_y$ is deeper than or equal to
that of the left-hand one. Thus, `(' and `)' correspond to `\\{push}'
and `\\{pop}'. Now if we want to assign a subscript to the final 1 in the
sequence
$$2_y\,7_d\,1_d\,(\,8_z\,2_y\,8_z\,)\,1$$
we cannot change the previous $1_d$ to $1_y$, since that would invalidate
the $2_y\ldots2_y$ hit. But we can change it to $1_z$, scoring a hit
since the intervening $8_z$'s are enclosed in parentheses.

The program below removes movement nodes that are introduced after a \\{push},
before it outputs the corresponding \\{pop}.

\Y\P\D \37$\\{y\_here}=1$\C{\\{info} when the movement entry points to a \|y
command}\par
\P\D \37$\\{z\_here}=2$\C{\\{info} when the movement entry points to a \|z
command}\par
\P\D \37$\\{yz\_OK}=3$\C{\\{info} corresponding to an unconstrained \\{down}
command}\par
\P\D \37$\\{y\_OK}=4$\C{\\{info} corresponding to a \\{down} that can't become
a \|z}\par
\P\D \37$\\{z\_OK}=5$\C{\\{info} corresponding to a \\{down} that can't become
a \|y}\par
\P\D \37$\\{d\_fixed}=6$\C{\\{info} corresponding to a \\{down} that can't
change}\par
\fi

\M609. When the \\{movement} procedure gets to the label \\{found}, the value
of
$\\{info}(\|p)$ will be either \\{y\_here} or \\{z\_here}. If it is, say, \\{y%
\_here},
the procedure generates a \\{y0} command (or a \\{w0} command), and marks
all \\{info} fields between \|q and \|p so that \|y is not OK in that range.

\Y\P$\4\X609:Generate a \\{y0} or \\{z0} command in order to reuse a previous
appearance of~\|w\X\S$\6
$\\{info}(\|q)\K\\{info}(\|p)$;\6
\&{if} $\\{info}(\|q)=\\{y\_here}$ \1\&{then}\6
\&{begin} \37$\\{dvi\_out}(\|o+\\{y0}-\\{down1})$;\C{\\{y0} or \\{w0}}\6
\&{while} $\\{link}(\|q)\I\|p$ \1\&{do}\6
\&{begin} \37$\|q\K\\{link}(\|q)$;\6
\&{case} $\\{info}(\|q)$ \1\&{of}\6
\4\\{yz\_OK}: \37$\\{info}(\|q)\K\\{z\_OK}$;\6
\4\\{y\_OK}: \37$\\{info}(\|q)\K\\{d\_fixed}$;\6
\4\&{othercases} \37\\{do\_nothing}\2\6
\&{endcases};\6
\&{end};\2\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{dvi\_out}(\|o+\\{z0}-\\{down1})$;\C{\\{z0} or %
\\{x0}}\6
\&{while} $\\{link}(\|q)\I\|p$ \1\&{do}\6
\&{begin} \37$\|q\K\\{link}(\|q)$;\6
\&{case} $\\{info}(\|q)$ \1\&{of}\6
\4\\{yz\_OK}: \37$\\{info}(\|q)\K\\{y\_OK}$;\6
\4\\{z\_OK}: \37$\\{info}(\|q)\K\\{d\_fixed}$;\6
\4\&{othercases} \37\\{do\_nothing}\2\6
\&{endcases};\6
\&{end};\2\6
\&{end}\2\par
\U section~607.\fi

\M610. \P$\X610:Generate a \\{down} or \\{right} command for \|w and \&{return}%
\X\S$\6
$\\{info}(\|q)\K\\{yz\_OK}$;\6
\&{if} $\\{abs}(\|w)\G\O{40000000}$ \1\&{then}\6
\&{begin} \37$\\{dvi\_out}(\|o+3)$;\C{\\{down4} or \\{right4}}\6
$\\{dvi\_four}(\|w)$;\5
\&{return};\6
\&{end};\2\6
\&{if} $\\{abs}(\|w)\G\O{100000}$ \1\&{then}\6
\&{begin} \37$\\{dvi\_out}(\|o+2)$;\C{\\{down3} or \\{right3}}\6
\&{if} $\|w<0$ \1\&{then}\5
$\|w\K\|w+\O{100000000}$;\2\6
$\\{dvi\_out}(\|w\mathbin{\&{div}}\O{200000})$;\5
$\|w\K\|w\mathbin{\&{mod}}\O{200000}$;\5
\&{goto} \372;\6
\&{end};\2\6
\&{if} $\\{abs}(\|w)\G\O{200}$ \1\&{then}\6
\&{begin} \37$\\{dvi\_out}(\|o+1)$;\C{\\{down2} or \\{right2}}\6
\&{if} $\|w<0$ \1\&{then}\5
$\|w\K\|w+\O{200000}$;\2\6
\&{goto} \372;\6
\&{end};\2\6
$\\{dvi\_out}(\|o)$;\C{\\{down1} or \\{right1}}\6
\&{if} $\|w<0$ \1\&{then}\5
$\|w\K\|w+\O{400}$;\2\6
\&{goto} \371;\6
\42: \37$\\{dvi\_out}(\|w\mathbin{\&{div}}\O{400})$;\6
\41: \37$\\{dvi\_out}(\|w\mathbin{\&{mod}}\O{400})$;\5
\&{return}\par
\U section~607.\fi

\M611. As we search through the stack, we are in one of three states,
\\{y\_seen}, \\{z\_seen}, or \\{none\_seen}, depending on whether we have
encountered \\{y\_here} or \\{z\_here} nodes. These states are encoded as
multiples of 6, so that they can be added to the \\{info} fields for quick
decision-making.

\Y\P\D \37$\\{none\_seen}=0$\C{no \\{y\_here} or \\{z\_here} nodes have been
encountered yet}\par
\P\D \37$\\{y\_seen}=6$\C{we have seen \\{y\_here} but not \\{z\_here}}\par
\P\D \37$\\{z\_seen}=12$\C{we have seen \\{z\_here} but not \\{y\_here}}\par
\Y\P$\4\X611:Look at the other stack entries until deciding what sort of %
\.{DVI} command to generate; \&{goto} \\{found} if node \|p is a ``hit''\X\S$\6
$\|p\K\\{link}(\|q)$;\5
$\\{mstate}\K\\{none\_seen}$;\6
\&{while} $\|p\I\\{null}$ \1\&{do}\6
\&{begin} \37\&{if} $\\{width}(\|p)=\|w$ \1\&{then}\5
\X612:Consider a node with matching width; \&{goto} \\{found} if it's a hit\X\6
\4\&{else} \&{case} $\\{mstate}+\\{info}(\|p)$ \1\&{of}\6
\4$\\{none\_seen}+\\{y\_here}$: \37$\\{mstate}\K\\{y\_seen}$;\6
\4$\\{none\_seen}+\\{z\_here}$: \37$\\{mstate}\K\\{z\_seen}$;\6
\4$\\{y\_seen}+\\{z\_here},\39\\{z\_seen}+\\{y\_here}$: \37\&{goto} \37\\{not%
\_found};\6
\4\&{othercases} \37\\{do\_nothing}\2\6
\&{endcases};\2\6
$\|p\K\\{link}(\|p)$;\6
\&{end};\2\6
\4\\{not\_found}: \37\par
\U section~607.\fi

\M612. We might find a valid hit in a \|y or \|z byte that is already gone
from the buffer. But we can't change bytes that are gone forever; ``the
moving finger writes, $\ldots\,\,$.''

\Y\P$\4\X612:Consider a node with matching width; \&{goto} \\{found} if it's a
hit\X\S$\6
\&{case} $\\{mstate}+\\{info}(\|p)$ \1\&{of}\6
\4$\\{none\_seen}+\\{yz\_OK},\39\\{none\_seen}+\\{y\_OK},\39\\{z\_seen}+\\{yz%
\_OK},\39\\{z\_seen}+\\{y\_OK}$: \37\hbox{}\6
\&{if} $\\{location}(\|p)<\\{dvi\_gone}$ \1\&{then}\5
\&{goto} \37\\{not\_found}\6
\4\&{else} \X613:Change buffered instruction to \|y or \|w and \&{goto} %
\\{found}\X;\2\6
\4$\\{none\_seen}+\\{z\_OK},\39\\{y\_seen}+\\{yz\_OK},\39\\{y\_seen}+\\{z%
\_OK}$: \37\hbox{}\6
\&{if} $\\{location}(\|p)<\\{dvi\_gone}$ \1\&{then}\5
\&{goto} \37\\{not\_found}\6
\4\&{else} \X614:Change buffered instruction to \|z or \|x and \&{goto} %
\\{found}\X;\2\6
\4$\\{none\_seen}+\\{y\_here},\39\\{none\_seen}+\\{z\_here},\39\\{y\_seen}+\\{z%
\_here},\39\\{z\_seen}+\\{y\_here}$: \37\&{goto} \37\\{found};\6
\4\&{othercases} \37\\{do\_nothing}\2\6
\&{endcases}\par
\U section~611.\fi

\M613. \P$\X613:Change buffered instruction to \|y or \|w and \&{goto} %
\\{found}\X\S$\6
\&{begin} \37$\|k\K\\{location}(\|p)-\\{dvi\_offset}$;\6
\&{if} $\|k<0$ \1\&{then}\5
$\|k\K\|k+\\{dvi\_buf\_size}$;\2\6
$\\{dvi\_buf}[\|k]\K\\{dvi\_buf}[\|k]+\\{y1}-\\{down1}$;\5
$\\{info}(\|p)\K\\{y\_here}$;\5
\&{goto} \37\\{found};\6
\&{end}\par
\U section~612.\fi

\M614. \P$\X614:Change buffered instruction to \|z or \|x and \&{goto} %
\\{found}\X\S$\6
\&{begin} \37$\|k\K\\{location}(\|p)-\\{dvi\_offset}$;\6
\&{if} $\|k<0$ \1\&{then}\5
$\|k\K\|k+\\{dvi\_buf\_size}$;\2\6
$\\{dvi\_buf}[\|k]\K\\{dvi\_buf}[\|k]+\\{z1}-\\{down1}$;\5
$\\{info}(\|p)\K\\{z\_here}$;\5
\&{goto} \37\\{found};\6
\&{end}\par
\U section~612.\fi

\M615. In case you are wondering when all the movement nodes are removed from
\TeX's memory, the answer is that they are recycled just before
\\{hlist\_out} and \\{vlist\_out} finish outputting a box. This restores the
down and right stacks to the state they were in before the box was output,
except that some \\{info}'s may have become more restrictive.

\Y\P\4\&{procedure}\1\  \37$\\{prune\_movements}(\|l:\\{integer})$;\C{delete
movement nodes with $\\{location}\G\|l$}\6
\4\&{label} \37$\\{done},\39\\{exit}$;\6
\4\&{var} \37\|p: \37\\{pointer};\C{node being deleted}\2\6
\&{begin} \37\&{while} $\\{down\_ptr}\I\\{null}$ \1\&{do}\6
\&{begin} \37\&{if} $\\{location}(\\{down\_ptr})<\|l$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
$\|p\K\\{down\_ptr}$;\5
$\\{down\_ptr}\K\\{link}(\|p)$;\5
$\\{free\_node}(\|p,\39\\{movement\_node\_size})$;\6
\&{end};\2\6
\4\\{done}: \37\&{while} $\\{right\_ptr}\I\\{null}$ \1\&{do}\6
\&{begin} \37\&{if} $\\{location}(\\{right\_ptr})<\|l$ \1\&{then}\5
\&{return};\2\6
$\|p\K\\{right\_ptr}$;\5
$\\{right\_ptr}\K\\{link}(\|p)$;\5
$\\{free\_node}(\|p,\39\\{movement\_node\_size})$;\6
\&{end};\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M616. The actual distances by which we want to move might be computed as the
sum of several separate movements. For example, there might be several
glue nodes in succession, or we might want to move right by the width of
some box plus some amount of glue. More importantly, the baselineskip
distances are computed in terms of glue together with the depth and
height of adjacent boxes, and we want the \.{DVI} file to lump these
three quantities together into a single motion.

Therefore \TeX\ maintains two pairs of global variables: \\{dvi\_h} and \\{dvi%
\_v}
are the \|h and \|v coordinates corresponding to the commands actually
output to the \.{DVI} file, while \\{cur\_h} and \\{cur\_v} are the coordinates
corresponding to the current state of the output routines. Coordinate
changes will accumulate in \\{cur\_h} and \\{cur\_v} without being reflected
in the output, until such a change becomes necessary or desirable; we
can call the \\{movement} procedure whenever we want to make $\\{dvi\_h}=\\{cur%
\_h}$
or $\\{dvi\_v}=\\{cur\_v}$.

The current font reflected in the \.{DVI} output is called \\{dvi\_f};
there is no need for a `\\{cur\_f}' variable.

The depth of nesting of \\{hlist\_out} and \\{vlist\_out} is called \\{cur\_s};
this is essentially the depth of \\{push} commands in the \.{DVI} output.

\Y\P\D \37$\\{synch\_h}\S$\1\6
\&{if} $\\{cur\_h}\I\\{dvi\_h}$ \1\&{then}\6
\&{begin} \37$\\{movement}(\\{cur\_h}-\\{dvi\_h},\39\\{right1})$;\5
$\\{dvi\_h}\K\\{cur\_h}$;\6
\&{end}\2\2\par
\P\D \37$\\{synch\_v}\S$\1\6
\&{if} $\\{cur\_v}\I\\{dvi\_v}$ \1\&{then}\6
\&{begin} \37$\\{movement}(\\{cur\_v}-\\{dvi\_v},\39\\{down1})$;\5
$\\{dvi\_v}\K\\{cur\_v}$;\6
\&{end}\2\2\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4$\\{dvi\_h},\39\\{dvi\_v}$: \37\\{scaled};\C{a \.{DVI} reader program thinks
we are here}\6
\4$\\{cur\_h},\39\\{cur\_v}$: \37\\{scaled};\C{\TeX\ thinks we are here}\6
\4\\{dvi\_f}: \37\\{internal\_font\_number};\C{the current font}\6
\4\\{cur\_s}: \37\\{integer};\C{current depth of output box nesting}\par
\fi

\M617. \P$\X617:Initialize variables as \\{ship\_out} begins\X\S$\6
$\\{dvi\_h}\K0$;\5
$\\{dvi\_v}\K0$;\5
$\\{cur\_h}\K\\{h\_offset}$;\5
$\\{dvi\_f}\K\\{null\_font}$;\5
$\\{cur\_s}\K-1$;\5
\\{ensure\_dvi\_open};\6
\&{if} $\\{total\_pages}=0$ \1\&{then}\6
\&{begin} \37$\\{dvi\_out}(\\{pre})$;\5
$\\{dvi\_out}(\\{id\_byte})$;\C{output the preamble}\6
$\\{dvi\_four}(25400000)$;\5
$\\{dvi\_four}(473628672)$;\C{conversion ratio for sp}\6
\\{prepare\_mag};\5
$\\{dvi\_four}(\\{mag})$;\C{magnification factor is frozen}\6
$\\{old\_setting}\K\\{selector}$;\5
$\\{selector}\K\\{new\_string}$;\5
$\\{print}(\.{"\ TeX\ output\ "})$;\5
$\\{print\_int}(\\{year})$;\5
$\\{print\_char}(\.{"."})$;\5
$\\{print\_two}(\\{month})$;\5
$\\{print\_char}(\.{"."})$;\5
$\\{print\_two}(\\{day})$;\5
$\\{print\_char}(\.{":"})$;\5
$\\{print\_two}(\\{time}\mathbin{\&{div}}60)$;\5
$\\{print\_two}(\\{time}\mathbin{\&{mod}}60)$;\5
$\\{selector}\K\\{old\_setting}$;\5
$\\{dvi\_out}(\\{cur\_length})$;\6
\&{for} $\|s\K\\{str\_start}[\\{str\_ptr}]\mathrel{\&{to}}\\{pool\_ptr}-1$ \1%
\&{do}\5
$\\{dvi\_out}(\\{str\_pool}[\|s])$;\2\6
$\\{pool\_ptr}\K\\{str\_start}[\\{str\_ptr}]$;\C{flush the current string}\6
\&{end}\2\par
\U section~640.\fi

\M618. When \\{hlist\_out} is called, its duty is to output the box represented
by the \\{hlist\_node} pointed to by \\{temp\_ptr}. The reference point of that
box has coordinates $(\\{cur\_h},\\{cur\_v})$.

Similarly, when \\{vlist\_out} is called, its duty is to output the box
represented
by the \\{vlist\_node} pointed to by \\{temp\_ptr}. The reference point of that
box has coordinates $(\\{cur\_h},\\{cur\_v})$.

\Y\P\4\&{procedure}\1\  \37\\{vlist\_out};\5
\\{forward};\C{\\{hlist\_out} and \\{vlist\_out} are mutually 	recursive}\par
\fi

\M619. The recursive procedures \\{hlist\_out} and \\{vlist\_out} each have
local variables
\\{save\_h} and \\{save\_v} to hold the values of \\{dvi\_h} and \\{dvi\_v}
just before
entering a new level of recursion.  In effect, the values of \\{save\_h} and
\\{save\_v} on \TeX's run-time stack correspond to the values of \|h and \|v
that a \.{DVI}-reading program will push onto its coordinate stack.

\Y\P\D \37$\\{move\_past}=13$\C{go to this label when advancing past glue or a
rule}\par
\P\D \37$\\{fin\_rule}=14$\C{go to this label to finish processing a rule}\par
\P\D \37$\\{next\_p}=15$\C{go to this label when finished with node \|p}\par
\Y\P\hbox{\4}\X1368:Declare procedures needed in \\{hlist\_out}, \\{vlist\_out}%
\X\hbox{}\6
\4\&{procedure}\1\  \37\\{hlist\_out};\C{output an \\{hlist\_node} box}\6
\4\&{label} \37$\\{reswitch},\39\\{move\_past},\39\\{fin\_rule},\39\\{next%
\_p}$;\6
\4\&{var} \37\\{base\_line}: \37\\{scaled};\C{the baseline coordinate for this
box}\6
\\{left\_edge}: \37\\{scaled};\C{the left coordinate for this box}\6
$\\{save\_h},\39\\{save\_v}$: \37\\{scaled};\C{what \\{dvi\_h} and \\{dvi\_v}
should pop to}\6
\\{this\_box}: \37\\{pointer};\C{pointer to containing box}\6
\\{g\_order}: \37\\{glue\_ord};\C{applicable order of infinity for glue}\6
\\{g\_sign}: \37$\\{normal}\to\\{shrinking}$;\C{selects type of glue}\6
\|p: \37\\{pointer};\C{current position in the hlist}\6
\\{save\_loc}: \37\\{integer};\C{\.{DVI} byte location upon entry}\6
\\{leader\_box}: \37\\{pointer};\C{the leader box being replicated}\6
\\{leader\_wd}: \37\\{scaled};\C{width of leader box being replicated}\6
\\{lx}: \37\\{scaled};\C{extra space between leader boxes}\6
\\{outer\_doing\_leaders}: \37\\{boolean};\C{were we doing leaders?}\6
\\{edge}: \37\\{scaled};\C{left edge of sub-box, or right edge of leader space}%
\2\6
\&{begin} \37$\\{this\_box}\K\\{temp\_ptr}$;\5
$\\{g\_order}\K\\{glue\_order}(\\{this\_box})$;\5
$\\{g\_sign}\K\\{glue\_sign}(\\{this\_box})$;\5
$\|p\K\\{list\_ptr}(\\{this\_box})$;\5
$\\{incr}(\\{cur\_s})$;\6
\&{if} $\\{cur\_s}>0$ \1\&{then}\5
$\\{dvi\_out}(\\{push})$;\2\6
\&{if} $\\{cur\_s}>\\{max\_push}$ \1\&{then}\5
$\\{max\_push}\K\\{cur\_s}$;\2\6
$\\{save\_loc}\K\\{dvi\_offset}+\\{dvi\_ptr}$;\5
$\\{base\_line}\K\\{cur\_v}$;\5
$\\{left\_edge}\K\\{cur\_h}$;\6
\&{while} $\|p\I\\{null}$ \1\&{do}\5
\X620\*:Output node \|p for \\{hlist\_out} and move to the next node,
maintaining the condition $\\{cur\_v}=\\{base\_line}$\X;\2\6
$\\{prune\_movements}(\\{save\_loc})$;\6
\&{if} $\\{cur\_s}>0$ \1\&{then}\5
$\\{dvi\_pop}(\\{save\_loc})$;\2\6
$\\{decr}(\\{cur\_s})$;\6
\&{end};\par
\fi

\M620\*. We ought to give special care to the efficiency of one part of %
\\{hlist\_out},
since it belongs to \TeX's inner loop. When a \\{char\_node} is encountered,
we save a little time by processing several nodes in succession until
reaching a non-\\{char\_node}. The program uses the fact that $\\{set\_char%
\_0}=0$.

\Y\P$\4\X620\*:Output node \|p for \\{hlist\_out} and move to the next node,
maintaining the condition $\\{cur\_v}=\\{base\_line}$\X\S$\6
\4\\{reswitch}: \37\&{if} $\\{is\_char\_node}(\|p)$ \1\&{then}\6
\&{begin} \37\\{synch\_h};\5
\\{synch\_v};\6
\1\&{repeat} \37\&{if} $\\{is\_xchar\_node}(\|p)$ \1\&{then}\6
\&{begin} \37$\|f\K\\{font}(\\{link}(\|p))$;\6
\&{if} $\\{character}(\|p)=\\{qi}(0)$ \1\&{then}\5
$\|p\K\\{link}(\|p)$;\C{bypass zero extension}\2\6
\&{end}\6
\4\&{else} $\|f\K\\{font}(\|p)$;\2\6
$\|c\K\\{character}(\|p)$;\6
\&{if} $\|f\I\\{dvi\_f}$ \1\&{then}\5
\X621:Change font \\{dvi\_f} to \|f\X;\2\6
\&{if} $\\{is\_xchar\_node}(\|p)$ \1\&{then}\6
\&{begin} \37$\\{dvi\_out}(\\{set1}+1)$;\5
$\\{dvi\_out}(\\{qo}(\|c))$;\5
$\|p\K\\{link}(\|p)$;\5
$\|c\K\\{character}(\|p)$;\6
\&{end}\6
\4\&{else} \&{if} $\|c\G\\{qi}(128)$ \1\&{then}\5
$\\{dvi\_out}(\\{set1})$;\2\2\6
$\\{dvi\_out}(\\{qo}(\|c))$;\6
$\\{cur\_h}\K\\{cur\_h}+\\{char\_width}(\|f)(\\{char\_info}(\|f)(\|c))$;\5
$\|p\K\\{link}(\|p)$;\6
\4\&{until}\5
$\R\\{is\_char\_node}(\|p)$;\2\6
$\\{dvi\_h}\K\\{cur\_h}$;\6
\&{end}\6
\4\&{else} \X622:Output the non-\\{char\_node} \|p for \\{hlist\_out} and move
to the next node\X\2\par
\U section~619.\fi

\M621. \P$\X621:Change font \\{dvi\_f} to \|f\X\S$\6
\&{begin} \37\&{if} $\R\\{font\_used}[\|f]$ \1\&{then}\6
\&{begin} \37$\\{dvi\_font\_def}(\|f)$;\5
$\\{font\_used}[\|f]\K\\{true}$;\6
\&{end};\2\6
\&{if} $\|f\L64+\\{font\_base}$ \1\&{then}\5
$\\{dvi\_out}(\|f-\\{font\_base}-1+\\{fnt\_num\_0})$\6
\4\&{else} \&{begin} \37$\\{dvi\_out}(\\{fnt1})$;\5
$\\{dvi\_out}(\|f-\\{font\_base}-1)$;\6
\&{end};\2\6
$\\{dvi\_f}\K\|f$;\6
\&{end}\par
\U section~620\*.\fi

\M622. \P$\X622:Output the non-\\{char\_node} \|p for \\{hlist\_out} and move
to the next node\X\S$\6
\&{begin} \37\&{case} $\\{type}(\|p)$ \1\&{of}\6
\4$\\{hlist\_node},\39\\{vlist\_node}$: \37\X623:Output a box in an hlist\X;\6
\4\\{rule\_node}: \37\&{begin} \37$\\{rule\_ht}\K\\{height}(\|p)$;\5
$\\{rule\_dp}\K\\{depth}(\|p)$;\5
$\\{rule\_wd}\K\\{width}(\|p)$;\5
\&{goto} \37\\{fin\_rule};\6
\&{end};\6
\4\\{whatsit\_node}: \37\X1366:Output the whatsit node \|p in an hlist\X;\6
\4\\{glue\_node}: \37\X625:Move right or output leaders\X;\6
\4$\\{kern\_node},\39\\{math\_node}$: \37$\\{cur\_h}\K\\{cur\_h}+\\{width}(%
\|p)$;\6
\4\\{ligature\_node}: \37\X652:Make node \|p look like a \\{char\_node} and %
\&{goto} \\{reswitch}\X;\6
\4\&{othercases} \37\\{do\_nothing}\2\6
\&{endcases};\6
\&{goto} \37\\{next\_p};\6
\4\\{fin\_rule}: \37\X624:Output a rule in an hlist\X;\6
\4\\{move\_past}: \37$\\{cur\_h}\K\\{cur\_h}+\\{rule\_wd}$;\6
\4\\{next\_p}: \37$\|p\K\\{link}(\|p)$;\6
\&{end}\par
\U section~620\*.\fi

\M623. \P$\X623:Output a box in an hlist\X\S$\6
\&{if} $\\{list\_ptr}(\|p)=\\{null}$ \1\&{then}\5
$\\{cur\_h}\K\\{cur\_h}+\\{width}(\|p)$\6
\4\&{else} \&{begin} \37$\\{save\_h}\K\\{dvi\_h}$;\5
$\\{save\_v}\K\\{dvi\_v}$;\5
$\\{cur\_v}\K\\{base\_line}+\\{shift\_amount}(\|p)$;\C{shift the box down}\6
$\\{temp\_ptr}\K\|p$;\5
$\\{edge}\K\\{cur\_h}$;\6
\&{if} $\\{type}(\|p)=\\{vlist\_node}$ \1\&{then}\5
\\{vlist\_out}\ \&{else} \\{hlist\_out};\2\6
$\\{dvi\_h}\K\\{save\_h}$;\5
$\\{dvi\_v}\K\\{save\_v}$;\5
$\\{cur\_h}\K\\{edge}+\\{width}(\|p)$;\5
$\\{cur\_v}\K\\{base\_line}$;\6
\&{end}\2\par
\U section~622.\fi

\M624. \P$\X624:Output a rule in an hlist\X\S$\6
\&{if} $\\{is\_running}(\\{rule\_ht})$ \1\&{then}\5
$\\{rule\_ht}\K\\{height}(\\{this\_box})$;\2\6
\&{if} $\\{is\_running}(\\{rule\_dp})$ \1\&{then}\5
$\\{rule\_dp}\K\\{depth}(\\{this\_box})$;\2\6
$\\{rule\_ht}\K\\{rule\_ht}+\\{rule\_dp}$;\C{this is the rule thickness}\6
\&{if} $(\\{rule\_ht}>0)\W(\\{rule\_wd}>0)$ \1\&{then}\C{we don't output empty
rules}\6
\&{begin} \37\\{synch\_h};\5
$\\{cur\_v}\K\\{base\_line}+\\{rule\_dp}$;\5
\\{synch\_v};\5
$\\{dvi\_out}(\\{set\_rule})$;\5
$\\{dvi\_four}(\\{rule\_ht})$;\5
$\\{dvi\_four}(\\{rule\_wd})$;\5
$\\{cur\_v}\K\\{base\_line}$;\5
$\\{dvi\_h}\K\\{dvi\_h}+\\{rule\_wd}$;\6
\&{end}\2\par
\U section~622.\fi

\M625. \P$\X625:Move right or output leaders\X\S$\6
\&{begin} \37$\|g\K\\{glue\_ptr}(\|p)$;\5
$\\{rule\_wd}\K\\{width}(\|g)$;\6
\&{if} $\\{g\_sign}\I\\{normal}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{g\_sign}=\\{stretching}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{stretch\_order}(\|g)=\\{g\_order}$ \1\&{then}\5
$\\{rule\_wd}\K\\{rule\_wd}+\\{round}(\\{float}(\\{glue\_set}(\\{this\_box}))%
\ast\\{stretch}(\|g))$;\2\6
\&{end}\6
\4\&{else} \&{begin} \37\&{if} $\\{shrink\_order}(\|g)=\\{g\_order}$ \1\&{then}%
\5
$\\{rule\_wd}\K\\{rule\_wd}-\\{round}(\\{float}(\\{glue\_set}(\\{this\_box}))%
\ast\\{shrink}(\|g))$;\2\6
\&{end};\2\6
\&{end};\2\6
\&{if} $\\{subtype}(\|p)\G\\{a\_leaders}$ \1\&{then}\5
\X626:Output leaders in an hlist, \&{goto} \\{fin\_rule} if a rule or to %
\\{next\_p} if done\X;\2\6
\&{goto} \37\\{move\_past};\6
\&{end}\par
\U section~622.\fi

\M626. \P$\X626:Output leaders in an hlist, \&{goto} \\{fin\_rule} if a rule or
to \\{next\_p} if done\X\S$\6
\&{begin} \37$\\{leader\_box}\K\\{leader\_ptr}(\|p)$;\6
\&{if} $\\{type}(\\{leader\_box})=\\{rule\_node}$ \1\&{then}\6
\&{begin} \37$\\{rule\_ht}\K\\{height}(\\{leader\_box})$;\5
$\\{rule\_dp}\K\\{depth}(\\{leader\_box})$;\5
\&{goto} \37\\{fin\_rule};\6
\&{end};\2\6
$\\{leader\_wd}\K\\{width}(\\{leader\_box})$;\6
\&{if} $(\\{leader\_wd}>0)\W(\\{rule\_wd}>0)$ \1\&{then}\6
\&{begin} \37$\\{edge}\K\\{cur\_h}+\\{rule\_wd}$;\5
$\\{lx}\K0$;\5
\X627:Let \\{cur\_h} be the position of the first box, and set $\\{leader\_wd}+%
\\{lx}$ to the spacing between corresponding parts of boxes\X;\6
\&{while} $\\{cur\_h}+\\{leader\_wd}\L\\{edge}$ \1\&{do}\5
\X628:Output a leader box at \\{cur\_h}, then advance \\{cur\_h} by $\\{leader%
\_wd}+\\{lx}$\X;\2\6
$\\{cur\_h}\K\\{edge}$;\5
\&{goto} \37\\{next\_p};\6
\&{end};\2\6
\&{end}\par
\U section~625.\fi

\M627. The calculations related to leaders require a bit of care. First, in the
case of \\{a\_leaders} (aligned leaders), we want to move \\{cur\_h} to
\\{left\_edge} plus the smallest multiple of \\{leader\_wd} for which the
result
is not less than the current value of \\{cur\_h}; i.e., \\{cur\_h} should
become
$\\{left\_edge}+\\{leader\_wd}\times\lceil
(\\{cur\_h}-\\{left\_edge})/\\{leader\_wd}\rceil$.  The program here should
work in
all cases even though some implementations of \PASCAL\ give nonstandard
results for the $\mathbin{\&{div}}$ operation when \\{cur\_h} is less than %
\\{left\_edge}.

In the case of \\{c\_leaders} (centered leaders), we want to increase \\{cur%
\_h}
by half of the excess space not occupied by the leaders; and in the
case of \\{x\_leaders} (expanded leaders) we increase \\{cur\_h}
by $1/(q+1)$ of this excess space, where $q$ is the number of times the
leader box will be replicated. Slight inaccuracies in the division might
accumulate; half of this rounding error is placed at each end of the leaders.

\Y\P$\4\X627:Let \\{cur\_h} be the position of the first box, and set $%
\\{leader\_wd}+\\{lx}$ to the spacing between corresponding parts of boxes\X\S$%
\6
\&{if} $\\{subtype}(\|p)=\\{a\_leaders}$ \1\&{then}\6
\&{begin} \37$\\{save\_h}\K\\{cur\_h}$;\5
$\\{cur\_h}\K\\{left\_edge}+\\{leader\_wd}\ast((\\{cur\_h}-\\{left\_edge})%
\mathbin{\&{div}}\\{leader\_wd})$;\6
\&{if} $\\{cur\_h}<\\{save\_h}$ \1\&{then}\5
$\\{cur\_h}\K\\{cur\_h}+\\{leader\_wd}$;\2\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{lq}\K\\{rule\_wd}\mathbin{\&{div}}\\{leader\_wd}$;%
\C{the number of box copies}\6
$\\{lr}\K\\{rule\_wd}\mathbin{\&{mod}}\\{leader\_wd}$;\C{the remaining space}\6
\&{if} $\\{subtype}(\|p)=\\{c\_leaders}$ \1\&{then}\5
$\\{cur\_h}\K\\{cur\_h}+(\\{lr}\mathbin{\&{div}}2)$\6
\4\&{else} \&{begin} \37$\\{lx}\K(2\ast\\{lr}+\\{lq}+1)\mathbin{\&{div}}(2\ast%
\\{lq}+2)$;\C{round$(\\{lr}/(\\{lq}+1))$}\6
$\\{cur\_h}\K\\{cur\_h}+((\\{lr}-(\\{lq}-1)\ast\\{lx})\mathbin{\&{div}}2)$;\6
\&{end};\2\6
\&{end}\2\par
\U section~626.\fi

\M628. The `\\{synch}' operations here are intended to decrease the number
of bytes needed to specify horizontal and vertical motion in the \.{DVI}
output.

\Y\P$\4\X628:Output a leader box at \\{cur\_h}, then advance \\{cur\_h} by $%
\\{leader\_wd}+\\{lx}$\X\S$\6
\&{begin} \37$\\{cur\_v}\K\\{base\_line}+\\{shift\_amount}(\\{leader\_box})$;\5
\\{synch\_v};\5
$\\{save\_v}\K\\{dvi\_v}$;\6
\\{synch\_h};\5
$\\{save\_h}\K\\{dvi\_h}$;\5
$\\{temp\_ptr}\K\\{leader\_box}$;\5
$\\{outer\_doing\_leaders}\K\\{doing\_leaders}$;\5
$\\{doing\_leaders}\K\\{true}$;\6
\&{if} $\\{type}(\\{leader\_box})=\\{vlist\_node}$ \1\&{then}\5
\\{vlist\_out}\ \&{else} \\{hlist\_out};\2\6
$\\{doing\_leaders}\K\\{outer\_doing\_leaders}$;\5
$\\{dvi\_v}\K\\{save\_v}$;\5
$\\{dvi\_h}\K\\{save\_h}$;\5
$\\{cur\_v}\K\\{save\_v}$;\5
$\\{cur\_h}\K\\{save\_h}+\\{leader\_wd}+\\{lx}$;\6
\&{end}\par
\U section~626.\fi

\M629. The \\{vlist\_out} routine is similar to \\{hlist\_out}, but a bit
simpler.

\Y\P\4\&{procedure}\1\  \37\\{vlist\_out};\C{output a \\{vlist\_node} box}\6
\4\&{label} \37$\\{move\_past},\39\\{fin\_rule},\39\\{next\_p}$;\6
\4\&{var} \37\\{left\_edge}: \37\\{scaled};\C{the left coordinate for this box}%
\6
\\{top\_edge}: \37\\{scaled};\C{the top coordinate for this box}\6
$\\{save\_h},\39\\{save\_v}$: \37\\{scaled};\C{what \\{dvi\_h} and \\{dvi\_v}
should pop to}\6
\\{this\_box}: \37\\{pointer};\C{pointer to containing box}\6
\\{g\_order}: \37\\{glue\_ord};\C{applicable order of infinity for glue}\6
\\{g\_sign}: \37$\\{normal}\to\\{shrinking}$;\C{selects type of glue}\6
\|p: \37\\{pointer};\C{current position in the vlist}\6
\\{save\_loc}: \37\\{integer};\C{\.{DVI} byte location upon entry}\6
\\{leader\_box}: \37\\{pointer};\C{the leader box being replicated}\6
\\{leader\_ht}: \37\\{scaled};\C{height of leader box being replicated}\6
\\{lx}: \37\\{scaled};\C{extra space between leader boxes}\6
\\{outer\_doing\_leaders}: \37\\{boolean};\C{were we doing leaders?}\6
\\{edge}: \37\\{scaled};\C{bottom boundary of leader space}\2\6
\&{begin} \37$\\{this\_box}\K\\{temp\_ptr}$;\5
$\\{g\_order}\K\\{glue\_order}(\\{this\_box})$;\5
$\\{g\_sign}\K\\{glue\_sign}(\\{this\_box})$;\5
$\|p\K\\{list\_ptr}(\\{this\_box})$;\5
$\\{incr}(\\{cur\_s})$;\6
\&{if} $\\{cur\_s}>0$ \1\&{then}\5
$\\{dvi\_out}(\\{push})$;\2\6
\&{if} $\\{cur\_s}>\\{max\_push}$ \1\&{then}\5
$\\{max\_push}\K\\{cur\_s}$;\2\6
$\\{save\_loc}\K\\{dvi\_offset}+\\{dvi\_ptr}$;\5
$\\{left\_edge}\K\\{cur\_h}$;\5
$\\{cur\_v}\K\\{cur\_v}-\\{height}(\\{this\_box})$;\5
$\\{top\_edge}\K\\{cur\_v}$;\6
\&{while} $\|p\I\\{null}$ \1\&{do}\5
\X630:Output node \|p for \\{vlist\_out} and move to the next node, maintaining
the condition $\\{cur\_h}=\\{left\_edge}$\X;\2\6
$\\{prune\_movements}(\\{save\_loc})$;\6
\&{if} $\\{cur\_s}>0$ \1\&{then}\5
$\\{dvi\_pop}(\\{save\_loc})$;\2\6
$\\{decr}(\\{cur\_s})$;\6
\&{end};\par
\fi

\M630. \P$\X630:Output node \|p for \\{vlist\_out} and move to the next node,
maintaining the condition $\\{cur\_h}=\\{left\_edge}$\X\S$\6
\&{begin} \37\&{if} $\\{is\_char\_node}(\|p)$ \1\&{then}\5
$\\{confusion}(\.{"vlistout"})$\6
\4\&{else} \X631:Output the non-\\{char\_node} \|p for \\{vlist\_out}\X;\2\6
\4\\{next\_p}: \37$\|p\K\\{link}(\|p)$;\6
\&{end}\par
\U section~629.\fi

\M631. \P$\X631:Output the non-\\{char\_node} \|p for \\{vlist\_out}\X\S$\6
\&{begin} \37\&{case} $\\{type}(\|p)$ \1\&{of}\6
\4$\\{hlist\_node},\39\\{vlist\_node}$: \37\X632:Output a box in a vlist\X;\6
\4\\{rule\_node}: \37\&{begin} \37$\\{rule\_ht}\K\\{height}(\|p)$;\5
$\\{rule\_dp}\K\\{depth}(\|p)$;\5
$\\{rule\_wd}\K\\{width}(\|p)$;\5
\&{goto} \37\\{fin\_rule};\6
\&{end};\6
\4\\{whatsit\_node}: \37\X1365:Output the whatsit node \|p in a vlist\X;\6
\4\\{glue\_node}: \37\X634:Move down or output leaders\X;\6
\4\\{kern\_node}: \37$\\{cur\_v}\K\\{cur\_v}+\\{width}(\|p)$;\6
\4\&{othercases} \37\\{do\_nothing}\2\6
\&{endcases};\6
\&{goto} \37\\{next\_p};\6
\4\\{fin\_rule}: \37\X633:Output a rule in a vlist, \&{goto} \\{next\_p}\X;\6
\4\\{move\_past}: \37$\\{cur\_v}\K\\{cur\_v}+\\{rule\_ht}$;\6
\&{end}\par
\U section~630.\fi

\M632. The \\{synch\_v} here allows the \.{DVI} output to use one-byte commands
for adjusting \|v in most cases, since the baselineskip distance will
usually be constant.

\Y\P$\4\X632:Output a box in a vlist\X\S$\6
\&{if} $\\{list\_ptr}(\|p)=\\{null}$ \1\&{then}\5
$\\{cur\_v}\K\\{cur\_v}+\\{height}(\|p)+\\{depth}(\|p)$\6
\4\&{else} \&{begin} \37$\\{cur\_v}\K\\{cur\_v}+\\{height}(\|p)$;\5
\\{synch\_v};\5
$\\{save\_h}\K\\{dvi\_h}$;\5
$\\{save\_v}\K\\{dvi\_v}$;\5
$\\{cur\_h}\K\\{left\_edge}+\\{shift\_amount}(\|p)$;\C{shift the box right}\6
$\\{temp\_ptr}\K\|p$;\6
\&{if} $\\{type}(\|p)=\\{vlist\_node}$ \1\&{then}\5
\\{vlist\_out}\ \&{else} \\{hlist\_out};\2\6
$\\{dvi\_h}\K\\{save\_h}$;\5
$\\{dvi\_v}\K\\{save\_v}$;\5
$\\{cur\_v}\K\\{save\_v}+\\{depth}(\|p)$;\5
$\\{cur\_h}\K\\{left\_edge}$;\6
\&{end}\2\par
\U section~631.\fi

\M633. \P$\X633:Output a rule in a vlist, \&{goto} \\{next\_p}\X\S$\6
\&{if} $\\{is\_running}(\\{rule\_wd})$ \1\&{then}\5
$\\{rule\_wd}\K\\{width}(\\{this\_box})$;\2\6
$\\{rule\_ht}\K\\{rule\_ht}+\\{rule\_dp}$;\C{this is the rule thickness}\6
$\\{cur\_v}\K\\{cur\_v}+\\{rule\_ht}$;\6
\&{if} $(\\{rule\_ht}>0)\W(\\{rule\_wd}>0)$ \1\&{then}\C{we don't output empty
rules}\6
\&{begin} \37\\{synch\_h};\5
\\{synch\_v};\5
$\\{dvi\_out}(\\{put\_rule})$;\5
$\\{dvi\_four}(\\{rule\_ht})$;\5
$\\{dvi\_four}(\\{rule\_wd})$;\6
\&{end};\2\6
\&{goto} \37\\{next\_p}\par
\U section~631.\fi

\M634. \P$\X634:Move down or output leaders\X\S$\6
\&{begin} \37$\|g\K\\{glue\_ptr}(\|p)$;\5
$\\{rule\_ht}\K\\{width}(\|g)$;\6
\&{if} $\\{g\_sign}\I\\{normal}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{g\_sign}=\\{stretching}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{stretch\_order}(\|g)=\\{g\_order}$ \1\&{then}\5
$\\{rule\_ht}\K\\{rule\_ht}+\\{round}(\\{float}(\\{glue\_set}(\\{this\_box}))%
\ast\\{stretch}(\|g))$;\2\6
\&{end}\6
\4\&{else} \&{begin} \37\&{if} $\\{shrink\_order}(\|g)=\\{g\_order}$ \1\&{then}%
\5
$\\{rule\_ht}\K\\{rule\_ht}-\\{round}(\\{float}(\\{glue\_set}(\\{this\_box}))%
\ast\\{shrink}(\|g))$;\2\6
\&{end};\2\6
\&{end};\2\6
\&{if} $\\{subtype}(\|p)\G\\{a\_leaders}$ \1\&{then}\5
\X635:Output leaders in a vlist, \&{goto} \\{fin\_rule} if a rule or to \\{next%
\_p} if done\X;\2\6
\&{goto} \37\\{move\_past};\6
\&{end}\par
\U section~631.\fi

\M635. \P$\X635:Output leaders in a vlist, \&{goto} \\{fin\_rule} if a rule or
to \\{next\_p} if done\X\S$\6
\&{begin} \37$\\{leader\_box}\K\\{leader\_ptr}(\|p)$;\6
\&{if} $\\{type}(\\{leader\_box})=\\{rule\_node}$ \1\&{then}\6
\&{begin} \37$\\{rule\_wd}\K\\{width}(\\{leader\_box})$;\5
$\\{rule\_dp}\K0$;\5
\&{goto} \37\\{fin\_rule};\6
\&{end};\2\6
$\\{leader\_ht}\K\\{height}(\\{leader\_box})+\\{depth}(\\{leader\_box})$;\6
\&{if} $(\\{leader\_ht}>0)\W(\\{rule\_ht}>0)$ \1\&{then}\6
\&{begin} \37$\\{edge}\K\\{cur\_v}+\\{rule\_ht}$;\5
$\\{lx}\K0$;\5
\X636:Let \\{cur\_v} be the position of the first box, and set $\\{leader\_ht}+%
\\{lx}$ to the spacing between corresponding parts of boxes\X;\6
\&{while} $\\{cur\_v}+\\{leader\_ht}\L\\{edge}$ \1\&{do}\5
\X637:Output a leader box at \\{cur\_v}, then advance \\{cur\_v} by $\\{leader%
\_ht}+\\{lx}$\X;\2\6
$\\{cur\_v}\K\\{edge}$;\5
\&{goto} \37\\{next\_p};\6
\&{end};\2\6
\&{end}\par
\U section~634.\fi

\M636. \P$\X636:Let \\{cur\_v} be the position of the first box, and set $%
\\{leader\_ht}+\\{lx}$ to the spacing between corresponding parts of boxes\X\S$%
\6
\&{if} $\\{subtype}(\|p)=\\{a\_leaders}$ \1\&{then}\6
\&{begin} \37$\\{save\_v}\K\\{cur\_v}$;\5
$\\{cur\_v}\K\\{top\_edge}+\\{leader\_ht}\ast((\\{cur\_v}-\\{top\_edge})%
\mathbin{\&{div}}\\{leader\_ht})$;\6
\&{if} $\\{cur\_v}<\\{save\_v}$ \1\&{then}\5
$\\{cur\_v}\K\\{cur\_v}+\\{leader\_ht}$;\2\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{lq}\K\\{rule\_ht}\mathbin{\&{div}}\\{leader\_ht}$;%
\C{the number of box copies}\6
$\\{lr}\K\\{rule\_ht}\mathbin{\&{mod}}\\{leader\_ht}$;\C{the remaining space}\6
\&{if} $\\{subtype}(\|p)=\\{c\_leaders}$ \1\&{then}\5
$\\{cur\_v}\K\\{cur\_v}+(\\{lr}\mathbin{\&{div}}2)$\6
\4\&{else} \&{begin} \37$\\{lx}\K(2\ast\\{lr}+\\{lq}+1)\mathbin{\&{div}}(2\ast%
\\{lq}+2)$;\C{round$(\\{lr}/(\\{lq}+1))$}\6
$\\{cur\_v}\K\\{cur\_v}+((\\{lr}-(\\{lq}-1)\ast\\{lx})\mathbin{\&{div}}2)$;\6
\&{end};\2\6
\&{end}\2\par
\U section~635.\fi

\M637. When we reach this part of the program, \\{cur\_v} indicates the top of
a
leader box, not its baseline.

\Y\P$\4\X637:Output a leader box at \\{cur\_v}, then advance \\{cur\_v} by $%
\\{leader\_ht}+\\{lx}$\X\S$\6
\&{begin} \37$\\{cur\_h}\K\\{left\_edge}+\\{shift\_amount}(\\{leader\_box})$;\5
\\{synch\_h};\5
$\\{save\_h}\K\\{dvi\_h}$;\6
$\\{cur\_v}\K\\{cur\_v}+\\{height}(\\{leader\_box})$;\5
\\{synch\_v};\5
$\\{save\_v}\K\\{dvi\_v}$;\5
$\\{temp\_ptr}\K\\{leader\_box}$;\5
$\\{outer\_doing\_leaders}\K\\{doing\_leaders}$;\5
$\\{doing\_leaders}\K\\{true}$;\6
\&{if} $\\{type}(\\{leader\_box})=\\{vlist\_node}$ \1\&{then}\5
\\{vlist\_out}\ \&{else} \\{hlist\_out};\2\6
$\\{doing\_leaders}\K\\{outer\_doing\_leaders}$;\5
$\\{dvi\_v}\K\\{save\_v}$;\5
$\\{dvi\_h}\K\\{save\_h}$;\5
$\\{cur\_h}\K\\{save\_h}$;\5
$\\{cur\_v}\K\\{save\_v}-\\{height}(\\{leader\_box})+\\{leader\_ht}+\\{lx}$;\6
\&{end}\par
\U section~635.\fi

\M638. The \\{hlist\_out} and \\{vlist\_out} procedures are now complete, so we
are
ready for the \\{ship\_out} routine that gets them started in the first place.

\Y\P\4\&{procedure}\1\  \37$\\{ship\_out}(\|p:\\{pointer})$;\C{output the box %
\|p}\6
\4\&{label} \37\\{done};\6
\4\&{var} \37\\{page\_loc}: \37\\{integer};\C{location of the current \\{bop}}\6
$\|j,\39\|k$: \37$0\to9$;\C{indices to first ten count registers}\6
\|s: \37\\{pool\_pointer};\C{index into \\{str\_pool}}\6
\\{old\_setting}: \37$0\to\\{max\_selector}$;\C{saved \\{selector} setting}\2\6
\&{begin} \37\&{if} $\\{tracing\_output}>0$ \1\&{then}\6
\&{begin} \37$\\{print\_nl}(\.{""})$;\5
\\{print\_ln};\5
$\\{print}(\.{"Completed\ box\ being\ shipped\ out"})$;\6
\&{end};\2\6
\&{if} $\\{term\_offset}>\\{max\_print\_line}-9$ \1\&{then}\5
\\{print\_ln}\6
\4\&{else} \&{if} $(\\{term\_offset}>0)\V(\\{file\_offset}>0)$ \1\&{then}\5
$\\{print\_char}(\.{"\ "})$;\2\2\6
$\\{print\_char}(\.{"["})$;\5
$\|j\K9$;\6
\&{while} $(\\{count}(\|j)=0)\W(\|j>0)$ \1\&{do}\5
$\\{decr}(\|j)$;\2\6
\&{for} $\|k\K0\mathrel{\&{to}}\|j$ \1\&{do}\6
\&{begin} \37$\\{print\_int}(\\{count}(\|k))$;\6
\&{if} $\|k<\|j$ \1\&{then}\5
$\\{print\_char}(\.{"."})$;\2\6
\&{end};\2\6
\\{update\_terminal};\6
\&{if} $\\{tracing\_output}>0$ \1\&{then}\6
\&{begin} \37$\\{print\_char}(\.{"]"})$;\5
\\{begin\_diagnostic};\5
$\\{show\_box}(\|p)$;\5
$\\{end\_diagnostic}(\\{true})$;\6
\&{end};\2\6
\X640:Ship box \|p out\X;\6
\&{if} $\\{tracing\_output}\L0$ \1\&{then}\5
$\\{print\_char}(\.{"]"})$;\2\6
$\\{dead\_cycles}\K0$;\5
\\{update\_terminal};\C{progress report}\6
\X639:Flush the box from memory, showing statistics if requested\X;\6
\&{end};\par
\fi

\M639. \P$\X639:Flush the box from memory, showing statistics if requested\X\S$%
\6
\&{stat} \37\&{if} $\\{tracing\_stats}>1$ \1\&{then}\6
\&{begin} \37$\\{print\_nl}(\.{"Memory\ usage\ before:\ "})$;\5
$\\{print\_int}(\\{var\_used})$;\5
$\\{print\_char}(\.{"\&"})$;\5
$\\{print\_int}(\\{dyn\_used})$;\5
$\\{print\_char}(\.{";"})$;\6
\&{end};\2\6
\&{tats}\6
$\\{flush\_node\_list}(\|p)$;\6
\&{stat} \37\&{if} $\\{tracing\_stats}>1$ \1\&{then}\6
\&{begin} \37$\\{print}(\.{"\ after:\ "})$;\5
$\\{print\_int}(\\{var\_used})$;\5
$\\{print\_char}(\.{"\&"})$;\5
$\\{print\_int}(\\{dyn\_used})$;\5
$\\{print}(\.{";\ still\ untouched:\ "})$;\5
$\\{print\_int}(\\{hi\_mem\_min}-\\{lo\_mem\_max}-1)$;\5
\\{print\_ln};\6
\&{end};\2\6
\&{tats}\par
\U section~638.\fi

\M640. \P$\X640:Ship box \|p out\X\S$\6
\X641:Update the values of \\{max\_h} and \\{max\_v}; but if the page is too
large, \&{goto} \\{done}\X;\6
\X617:Initialize variables as \\{ship\_out} begins\X;\6
$\\{page\_loc}\K\\{dvi\_offset}+\\{dvi\_ptr}$;\5
$\\{dvi\_out}(\\{bop})$;\6
\&{for} $\|k\K0\mathrel{\&{to}}9$ \1\&{do}\5
$\\{dvi\_four}(\\{count}(\|k))$;\2\6
$\\{dvi\_four}(\\{last\_bop})$;\5
$\\{last\_bop}\K\\{page\_loc}$;\5
$\\{cur\_v}\K\\{height}(\|p)+\\{v\_offset}$;\5
$\\{temp\_ptr}\K\|p$;\6
\&{if} $\\{type}(\|p)=\\{vlist\_node}$ \1\&{then}\5
\\{vlist\_out}\ \&{else} \\{hlist\_out};\2\6
$\\{dvi\_out}(\\{eop})$;\5
$\\{incr}(\\{total\_pages})$;\6
\4\\{done}: \37\par
\U section~638.\fi

\M641. Sometimes the user will generate a huge page because other error
messages
are being ignored. Such pages are not output to the \.{dvi} file, since they
may confuse the printing software.

\Y\P$\4\X641:Update the values of \\{max\_h} and \\{max\_v}; but if the page is
too large, \&{goto} \\{done}\X\S$\6
\&{if} $(\\{height}(\|p)>\\{max\_dimen})\V\30(\\{depth}(\|p)>\\{max\_dimen})\V%
\30(\\{height}(\|p)+\\{depth}(\|p)+\\{v\_offset}>\\{max\_dimen})\V\30(%
\\{width}(\|p)+\\{h\_offset}>\\{max\_dimen})$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Huge\ page\ cannot\ be\ shipped\ out"})$;\5
$\\{help2}(\.{"The\ page\ just\ created\ is\ more\ than\ 18\ feet\ tall\ or"})$%
\6
$(\.{"more\ than\ 18\ feet\ wide,\ so\ I\ suspect\ something\ went\ wrong."})$;%
\5
\\{error};\6
\&{if} $\\{tracing\_output}\L0$ \1\&{then}\6
\&{begin} \37\\{begin\_diagnostic};\5
$\\{print\_nl}(\.{"The\ following\ box\ has\ been\ deleted:"})$;\5
$\\{show\_box}(\|p)$;\5
$\\{end\_diagnostic}(\\{true})$;\6
\&{end};\2\6
\&{goto} \37\\{done};\6
\&{end};\2\6
\&{if} $\\{height}(\|p)+\\{depth}(\|p)+\\{v\_offset}>\\{max\_v}$ \1\&{then}\5
$\\{max\_v}\K\\{height}(\|p)+\\{depth}(\|p)+\\{v\_offset}$;\2\6
\&{if} $\\{width}(\|p)+\\{h\_offset}>\\{max\_h}$ \1\&{then}\5
$\\{max\_h}\K\\{width}(\|p)+\\{h\_offset}$\2\par
\U section~640.\fi

\M642\*. At the end of the program, we must finish things off by writing the
post\-amble. If $\\{total\_pages}=0$, the \.{DVI} file was never opened.

An integer variable \|k will be declared for use by this routine.

\Y\P$\4\X642\*:Finish the \.{DVI} file\X\S$\6
\&{if} $\\{total\_pages}=0$ \1\&{then}\5
$\\{print\_nl}(\.{"No\ pages\ of\ output."})$\6
\4\&{else} \&{begin} \37$\\{dvi\_out}(\\{post})$;\C{beginning of the postamble}%
\6
$\\{dvi\_four}(\\{last\_bop})$;\5
$\\{last\_bop}\K\\{dvi\_offset}+\\{dvi\_ptr}-5$;\C{\\{post} location}\6
$\\{dvi\_four}(25400000)$;\5
$\\{dvi\_four}(473628672)$;\C{conversion ratio for sp}\6
\\{prepare\_mag};\5
$\\{dvi\_four}(\\{mag})$;\C{magnification factor}\6
$\\{dvi\_four}(\\{max\_v})$;\5
$\\{dvi\_four}(\\{max\_h})$;\6
$\\{dvi\_out}(\\{max\_push}\mathbin{\&{div}}256)$;\5
$\\{dvi\_out}(\\{max\_push}\mathbin{\&{mod}}256)$;\6
$\\{dvi\_out}(\\{total\_pages}\mathbin{\&{div}}256)$;\5
$\\{dvi\_out}(\\{total\_pages}\mathbin{\&{mod}}256)$;\6
\X643:Output the font definitions for all fonts that were used\X;\6
$\\{dvi\_out}(\\{post\_post})$;\5
$\\{dvi\_four}(\\{last\_bop})$;\5
$\\{dvi\_out}(\\{id\_byte})$;\6
$\|k\K4+((\\{dvi\_buf\_size}-\\{dvi\_ptr})\mathbin{\&{mod}}4)$;\C{the number of
223's}\6
\&{while} $\|k>0$ \1\&{do}\6
\&{begin} \37$\\{dvi\_out}(223)$;\5
$\\{decr}(\|k)$;\6
\&{end};\2\6
\X599:Empty the last bytes out of \\{dvi\_buf}\X;\6
$\\{print\_nl}(\.{"Output\ written\ on\ "})$;\5
$\\{print}(\\{output\_file\_name})$;\5
$\\{print}(\.{"\ ("})$;\5
$\\{print\_int}(\\{total\_pages})$;\5
$\\{print}(\.{"\ page"})$;\6
\&{if} $\\{total\_pages}\I1$ \1\&{then}\5
$\\{print\_char}(\.{"s"})$;\2\6
$\\{print}(\.{",\ "})$;\5
$\\{print\_int}(\\{dvi\_offset}+\\{dvi\_ptr})$;\5
$\\{print}(\.{"\ bytes)."})$;\5
$\\{b\_close}(\\{dvi\_file})$;\6
\&{if} $\\{pseudo\_typein}=0$ \1\&{then}\6
\&{begin} \37$\|k\K\\{selector}$;\5
$\\{selector}\K\\{new\_string}$;\5
$\\{pool\_ptr}\K\\{str\_start}[\\{str\_ptr}]$;\5
$\\{print}(\.{"r\ DVIdover;"})$;\5
$\\{print}(\\{output\_file\_name})$;\5
$\\{selector}\K\|k$;\6
\&{if} $\\{pool\_ptr}<\\{pool\_size}$ \1\&{then}\6
\&{if} $\\{str\_ptr}<\\{max\_strings}$ \1\&{then}\C{\\{overflow} can't occur}\6
$\\{pseudo\_typein}\K\\{make\_string}$;\2\2\6
\&{end};\2\6
\&{end}\2\par
\U section~1333\*.\fi

\M643. \P$\X643:Output the font definitions for all fonts that were used\X\S$\6
\&{while} $\\{font\_ptr}>\\{font\_base}$ \1\&{do}\6
\&{begin} \37\&{if} $\\{font\_used}[\\{font\_ptr}]$ \1\&{then}\5
$\\{dvi\_font\_def}(\\{font\_ptr})$;\2\6
$\\{decr}(\\{font\_ptr})$;\6
\&{end}\2\par
\U section~642\*.\fi

\N644.  \[33] Packaging.
We're essentially done with the parts of \TeX\ that are concerned with
the input (\\{get\_next}) and the output (\\{ship\_out}). So it's time to
get heavily into the remaining part, which does the real work of typesetting.

After lists are constructed, \TeX\ wraps them up and puts them into boxes.
Two major subroutines are given the responsibility for this task: \\{hpack}
applies to horizontal lists (hlists) and \\{vpack} applies to vertical lists
(vlists). The main duty of \\{hpack} and \\{vpack} is to compute the dimensions
of the resulting boxes, and to adjust the glue if one of those dimensions
is pre-specified. The computed sizes normally enclose all of the material
inside the new box; but some items may stick out if negative glue is used,
if the box is overfull, or if a \.{\\vbox} includes other boxes that have
been shifted left.

The subroutine call $\\{hpack}(\|p,\|w,\|m)$ returns a pointer to an \\{hlist%
\_node}
for a box containing the hlist that starts at \|p. Parameter \|w specifies
a width; and parameter \|m is either `\\{exactly}' or `\\{additional}'.  Thus,
$\\{hpack}(\|p,\|w,\\{exactly})$ produces a box whose width is exactly \|w,
while
$\\{hpack}(\|p,\|w,\\{additional})$ yields a box whose width is the natural
width plus
\|w.  It is convenient to define a macro called `\\{natural}' to cover the
most common case, so that we can say $\\{hpack}(\|p,\\{natural})$ to get a box
that
has the natural width of list \|p.

Similarly, $\\{vpack}(\|p,\|w,\|m)$ returns a pointer to a \\{vlist\_node} for
a
box containing the vlist that starts at \|p. In this case \|w represents
a height instead of a width; the parameter \|m is interpreted as in \\{hpack}.

\Y\P\D \37$\\{exactly}=0$\C{a box dimension is pre-specified}\par
\P\D \37$\\{additional}=1$\C{a box dimension is increased from the natural one}%
\par
\P\D \37$\\{natural}\S0,\39\\{additional}$\C{shorthand for parameters to %
\\{hpack} and \\{vpack}}\par
\fi

\M645. The parameters to \\{hpack} and \\{vpack} correspond to \TeX's
primitives
like `\.{\\hbox} \.{to} \.{300pt}', `\.{\\hbox} \.{spread} \.{10pt}'; note
that `\.{\\hbox}' with no dimension following it is equivalent to
`\.{\\hbox} \.{spread} \.{0pt}'.  The \\{scan\_spec} subroutine scans such
constructions in the user's input, including the mandatory left brace that
follows them, and it puts the specification onto \\{save\_stack} so that the
desired box can later be obtained by executing the following code:
$$\vbox{\halign{#\hfil\cr
$\\{save\_ptr}\K\\{save\_ptr}-2$;\cr
$\\{hpack}(\|p,\\{saved}(1),\\{saved}(0)).$\cr}}$$

\Y\P\4\&{procedure}\1\  \37\\{scan\_spec};\C{scans a box specification and left
brace}\6
\4\&{label} \37\\{found};\2\6
\&{begin} \37\&{if} $\\{scan\_keyword}(\.{"to"})$ \1\&{then}\5
$\\{saved}(0)\K\\{exactly}$\6
\4\&{else} \&{if} $\\{scan\_keyword}(\.{"spread"})$ \1\&{then}\5
$\\{saved}(0)\K\\{additional}$\6
\4\&{else} \&{begin} \37$\\{saved}(0)\K\\{additional}$;\5
$\\{saved}(1)\K0$;\5
\&{goto} \37\\{found};\6
\&{end};\2\2\6
\\{scan\_normal\_dimen};\5
$\\{saved}(1)\K\\{cur\_val}$;\6
\4\\{found}: \37$\\{save\_ptr}\K\\{save\_ptr}+2$;\5
\\{scan\_left\_brace};\6
\&{end};\par
\fi

\M646. To figure out the glue setting, \\{hpack} and \\{vpack} determine how
much
stretchability and shrinkability are present, considering all four orders
of infinity. The highest order of infinity that has a nonzero coefficient
is then used as if no other orders were present.

For example, suppose that the given list contains six glue nodes with
the respective stretchabilities 3pt, 8fill, 5fil, 6pt, $-3$fil, $-8$fill.
Then the total is essentially 2fil; and if a total additional space of 6pt
is to be achieved by stretching, the actual amounts of stretch will be
0pt, 0pt, 15pt, 0pt, $-9$pt, and 0pt, since only `fil' glue will be
considered. (The `fill' glue is therefore not really stretching infinitely
with respect to `fil'; nobody would actually want that to happen.)

The arrays \\{total\_stretch} and \\{total\_shrink} are used to determine how
much
glue of each kind is present.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4$\\{total\_stretch},\39\\{total\_shrink}$: \37\&{array} $[\\{glue\_ord}]$ \1%
\&{of}\5
\\{scaled};\C{glue found by \\{hpack} or \\{vpack}}\2\par
\fi

\M647. If the global variable \\{adjust\_tail} is non-null, the \\{hpack}
routine
also removes all occurrences of \\{ins\_node}, \\{mark\_node}, and \\{adjust%
\_node}
items and appends the resulting material onto the list that ends at
location \\{adjust\_tail}.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{adjust\_tail}: \37\\{pointer};\C{tail of adjustment list}\par
\fi

\M648. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{adjust\_tail}\K\\{null}$;\par
\fi

\M649. Here now is \\{hpack}, which contains few if any surprises.

\Y\P\4\&{function}\1\  \37$\\{hpack}(\|p:\\{pointer};\,\35\|w:\\{scaled};\,\35%
\|m:\\{small\_number})$: \37\\{pointer};\6
\4\&{label} \37$\\{reswitch},\39\\{common\_ending},\39\\{exit}$;\6
\4\&{var} \37\|r: \37\\{pointer};\C{the box node that will be returned}\6
\|q: \37\\{pointer};\C{trails behind \|p}\6
$\|h,\39\|d,\39\|x$: \37\\{scaled};\C{height, depth, and natural width}\6
\|s: \37\\{scaled};\C{shift amount}\6
\|g: \37\\{pointer};\C{points to a glue specification}\6
\|o: \37\\{glue\_ord};\C{order of infinity}\6
\|f: \37\\{internal\_font\_number};\C{the font in a \\{char\_node}}\6
\|i: \37\\{four\_quarters};\C{font information about a \\{char\_node}}\6
\\{hd}: \37\\{eight\_bits};\C{height and depth indices for a character}\6
\|b: \37\\{integer};\C{badness of the new box}\2\6
\&{begin} \37$\|r\K\\{get\_node}(\\{box\_node\_size})$;\5
$\\{type}(\|r)\K\\{hlist\_node}$;\5
$\\{subtype}(\|r)\K\\{min\_quarterword}$;\5
$\\{shift\_amount}(\|r)\K0$;\5
$\|q\K\|r+\\{list\_offset}$;\5
$\\{link}(\|q)\K\|p$;\6
$\|h\K0$;\5
\X650:Clear dimensions to zero\X;\6
\&{while} $\|p\I\\{null}$ \1\&{do}\5
\X651:Examine node \|p in the hlist, taking account of its effect on the
dimensions of the new box, or moving it to the adjustment list; then advance %
\|p to the next node\X;\2\6
\&{if} $\\{adjust\_tail}\I\\{null}$ \1\&{then}\5
$\\{link}(\\{adjust\_tail})\K\\{null}$;\2\6
$\\{height}(\|r)\K\|h$;\5
$\\{depth}(\|r)\K\|d$;\6
\X657:Determine the value of $\\{width}(\|r)$ and the appropriate glue setting;
then \&{return} or \&{goto} \\{common\_ending}\X;\6
\4\\{common\_ending}: \37\X663\*:Finish issuing a diagnostic message for an
overfull or underfull hbox\X;\6
\4\\{exit}: \37$\\{hpack}\K\|r$;\6
\&{end};\par
\fi

\M650. \P$\X650:Clear dimensions to zero\X\S$\6
$\|d\K0$;\5
$\|x\K0$;\5
$\\{total\_stretch}[\\{normal}]\K0$;\5
$\\{total\_shrink}[\\{normal}]\K0$;\5
$\\{total\_stretch}[\\{fil}]\K0$;\5
$\\{total\_shrink}[\\{fil}]\K0$;\5
$\\{total\_stretch}[\\{fill}]\K0$;\5
$\\{total\_shrink}[\\{fill}]\K0$;\5
$\\{total\_stretch}[\\{filll}]\K0$;\5
$\\{total\_shrink}[\\{filll}]\K0$\par
\U sections~649 and~668.\fi

\M651. \P$\X651:Examine node \|p in the hlist, taking account of its effect on
the dimensions of the new box, or moving it to the adjustment list; then
advance \|p to the next node\X\S$\6
\&{begin} \37\\{reswitch}: \37\&{while} $\\{is\_char\_node}(\|p)$ \1\&{do}\5
\X654\*:Incorporate character dimensions into the dimensions of the hbox that
will contain~it, then move to the next node\X;\2\6
\&{if} $\|p\I\\{null}$ \1\&{then}\6
\&{begin} \37\&{case} $\\{type}(\|p)$ \1\&{of}\6
\4$\\{hlist\_node},\39\\{vlist\_node},\39\\{rule\_node},\39\\{unset\_node}$: %
\37\X653:Incorporate box dimensions into the dimensions of the hbox that will
contain~it\X;\6
\4$\\{ins\_node},\39\\{mark\_node},\39\\{adjust\_node}$: \37\&{if} $\\{adjust%
\_tail}\I\\{null}$ \1\&{then}\5
\X655:Transfer node \|p to the adjustment list\X;\2\6
\4\\{whatsit\_node}: \37\X1360:Incorporate a whatsit node into an hbox\X;\6
\4\\{glue\_node}: \37\X656:Incorporate glue into the horizontal totals\X;\6
\4$\\{kern\_node},\39\\{math\_node}$: \37$\|x\K\|x+\\{width}(\|p)$;\6
\4\\{ligature\_node}: \37\X652:Make node \|p look like a \\{char\_node} and %
\&{goto} \\{reswitch}\X;\6
\4\&{othercases} \37\\{do\_nothing}\2\6
\&{endcases};\6
$\|p\K\\{link}(\|p)$;\6
\&{end};\2\6
\&{end}\par
\U section~649.\fi

\M652. \P$\X652:Make node \|p look like a \\{char\_node} and \&{goto} %
\\{reswitch}\X\S$\6
\&{begin} \37$\\{mem}[\\{lig\_trick}]\K\\{mem}[\\{lig\_char}(\|p)]$;\5
$\\{link}(\\{lig\_trick})\K\\{link}(\|p)$;\5
$\|p\K\\{lig\_trick}$;\5
\&{goto} \37\\{reswitch};\6
\&{end}\par
\U sections~622, 651, and~1147\*.\fi

\M653. The code here implicitly uses the fact that running dimensions are
indicated by \\{null\_flag}, which will be ignored in the calculations
because it is a highly negative number.

\Y\P$\4\X653:Incorporate box dimensions into the dimensions of the hbox that
will contain~it\X\S$\6
\&{begin} \37$\|x\K\|x+\\{width}(\|p)$;\6
\&{if} $\\{type}(\|p)\G\\{rule\_node}$ \1\&{then}\5
$\|s\K0$\ \&{else} $\|s\K\\{shift\_amount}(\|p)$;\2\6
\&{if} $\\{height}(\|p)-\|s>\|h$ \1\&{then}\5
$\|h\K\\{height}(\|p)-\|s$;\2\6
\&{if} $\\{depth}(\|p)+\|s>\|d$ \1\&{then}\5
$\|d\K\\{depth}(\|p)+\|s$;\2\6
\&{end}\par
\U section~651.\fi

\M654\*. The following code is part of \TeX's inner loop; i.e., adding another
character of text to the user's input will cause each of these instructions
to be exercised one more time.

\Y\P$\4\X654\*:Incorporate character dimensions into the dimensions of the hbox
that will contain~it, then move to the next node\X\S$\6
\&{begin} \37$\\{bypass\_xchar}(\|p)$;\5
$\|f\K\\{font}(\|p)$;\5
$\|i\K\\{char\_info}(\|f)(\\{character}(\|p))$;\5
$\\{hd}\K\\{height\_depth}(\|i)$;\5
$\|x\K\|x+\\{char\_width}(\|f)(\|i)$;\6
$\|s\K\\{char\_height}(\|f)(\\{hd})$;\ \&{if} $\|s>\|h$ \1\&{then}\5
$\|h\K\|s$;\2\6
$\|s\K\\{char\_depth}(\|f)(\\{hd})$;\ \&{if} $\|s>\|d$ \1\&{then}\5
$\|d\K\|s$;\2\6
$\|p\K\\{link}(\|p)$;\6
\&{end}\par
\U section~651.\fi

\M655. Although node \|q is not necessarily the immediate predecessor of node %
\|p,
it always points to some node in the list preceding \|p. Thus, we can delete
nodes by moving \|q when necessary. The algorithm takes linear time, and the
extra computation does not intrude on the inner loop unless it is necessary
to make a deletion.

\Y\P$\4\X655:Transfer node \|p to the adjustment list\X\S$\6
\&{begin} \37\&{while} $\\{link}(\|q)\I\|p$ \1\&{do}\5
$\|q\K\\{link}(\|q)$;\2\6
\&{if} $\\{type}(\|p)=\\{adjust\_node}$ \1\&{then}\6
\&{begin} \37$\\{link}(\\{adjust\_tail})\K\\{adjust\_ptr}(\|p)$;\6
\&{while} $\\{link}(\\{adjust\_tail})\I\\{null}$ \1\&{do}\5
$\\{adjust\_tail}\K\\{link}(\\{adjust\_tail})$;\2\6
$\|p\K\\{link}(\|p)$;\5
$\\{free\_node}(\\{link}(\|q),\39\\{small\_node\_size})$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{link}(\\{adjust\_tail})\K\|p$;\5
$\\{adjust\_tail}\K\|p$;\5
$\|p\K\\{link}(\|p)$;\6
\&{end};\2\6
$\\{link}(\|q)\K\|p$;\5
$\|p\K\|q$;\6
\&{end}\par
\U section~651.\fi

\M656. \P$\X656:Incorporate glue into the horizontal totals\X\S$\6
\&{begin} \37$\|g\K\\{glue\_ptr}(\|p)$;\5
$\|x\K\|x+\\{width}(\|g)$;\6
$\|o\K\\{stretch\_order}(\|g)$;\5
$\\{total\_stretch}[\|o]\K\\{total\_stretch}[\|o]+\\{stretch}(\|g)$;\5
$\|o\K\\{shrink\_order}(\|g)$;\5
$\\{total\_shrink}[\|o]\K\\{total\_shrink}[\|o]+\\{shrink}(\|g)$;\6
\&{if} $\\{subtype}(\|p)\G\\{a\_leaders}$ \1\&{then}\6
\&{begin} \37$\|g\K\\{leader\_ptr}(\|p)$;\6
\&{if} $\\{height}(\|g)>\|h$ \1\&{then}\5
$\|h\K\\{height}(\|g)$;\2\6
\&{if} $\\{depth}(\|g)>\|d$ \1\&{then}\5
$\|d\K\\{depth}(\|g)$;\2\6
\&{end};\2\6
\&{end}\par
\U section~651.\fi

\M657. When we get to the present part of the program, \|x is the natural width
of the box being packaged.

\Y\P$\4\X657:Determine the value of $\\{width}(\|r)$ and the appropriate glue
setting; then \&{return} or \&{goto} \\{common\_ending}\X\S$\6
\&{if} $\|m=\\{additional}$ \1\&{then}\5
$\|w\K\|x+\|w$;\2\6
$\\{width}(\|r)\K\|w$;\5
$\|x\K\|w-\|x$;\C{now \|x is the excess to be made up}\6
\&{if} $\|x=0$ \1\&{then}\6
\&{begin} \37$\\{glue\_sign}(\|r)\K\\{normal}$;\5
$\\{glue\_order}(\|r)\K\\{normal}$;\5
$\\{set\_glue\_ratio\_zero}(\\{glue\_set}(\|r))$;\5
\&{return};\6
\&{end}\6
\4\&{else} \&{if} $\|x>0$ \1\&{then}\5
\X658:Determine horizontal glue stretch setting, then \&{return} or \hbox{%
\&{goto} \\{common\_ending}}\X\6
\4\&{else} \X664:Determine horizontal glue shrink setting, then \&{return} or %
\hbox{\&{goto} \\{common\_ending}}\X\2\2\par
\U section~649.\fi

\M658. \P$\X658:Determine horizontal glue stretch setting, then \&{return} or %
\hbox{\&{goto} \\{common\_ending}}\X\S$\6
\&{begin} \37\X659:Determine the stretch order\X;\6
$\\{glue\_order}(\|r)\K\|o$;\5
$\\{glue\_sign}(\|r)\K\\{stretching}$;\6
\&{if} $\\{total\_stretch}[\|o]\I0$ \1\&{then}\5
$\\{glue\_set}(\|r)\K\\{unfloat}(\|x/\\{total\_stretch}[\|o])$\6
\4\&{else} \&{begin} \37$\\{glue\_sign}(\|r)\K\\{normal}$;\5
$\\{set\_glue\_ratio\_zero}(\\{glue\_set}(\|r))$;\C{there's nothing to stretch}%
\6
\&{end};\2\6
\&{if} $(\\{hbadness}<\\{inf\_bad})\W(\|o=\\{normal})\W(\\{list\_ptr}(\|r)\I%
\\{null})$ \1\&{then}\5
\X660:Report an underfull hbox and \&{goto} \\{common\_ending}, if this box is
sufficiently bad\X;\2\6
\&{return};\6
\&{end}\par
\U section~657.\fi

\M659. \P$\X659:Determine the stretch order\X\S$\6
\&{if} $\\{total\_stretch}[\\{filll}]\I0$ \1\&{then}\5
$\|o\K\\{filll}$\6
\4\&{else} \&{if} $\\{total\_stretch}[\\{fill}]\I0$ \1\&{then}\5
$\|o\K\\{fill}$\6
\4\&{else} \&{if} $\\{total\_stretch}[\\{fil}]\I0$ \1\&{then}\5
$\|o\K\\{fil}$\6
\4\&{else} $\|o\K\\{normal}$\2\2\2\par
\U sections~658, 673, and~796.\fi

\M660. \P$\X660:Report an underfull hbox and \&{goto} \\{common\_ending}, if
this box is sufficiently bad\X\S$\6
\&{begin} \37$\|b\K\\{badness}(\|x,\39\\{total\_stretch}[\\{normal}])$;\6
\&{if} $\|b>\\{hbadness}$ \1\&{then}\6
\&{begin} \37\\{print\_ln};\6
\&{if} $\|b>100$ \1\&{then}\5
$\\{print\_nl}(\.{"Underfull"})$\ \&{else} $\\{print\_nl}(\.{"Loose"})$;\2\6
$\\{print}(\.{"\ \\hbox\ (badness\ "})$;\5
$\\{print\_int}(\|b)$;\5
\&{goto} \37\\{common\_ending};\6
\&{end};\2\6
\&{end}\par
\U section~658.\fi

\M661. In order to provide a decent indication of where an overfull or
underfull
box originated, we use a global variable \\{pack\_begin\_line} that is
set nonzero only when \\{hpack} is being called by the paragraph builder
or the alignment finishing routine.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{pack\_begin\_line}: \37\\{integer};\C{source file line where the current
paragraph 	or alignment began; a negative value denotes alignment}\par
\fi

\M662. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{pack\_begin\_line}\K0$;\par
\fi

\M663\*. \P$\X663\*:Finish issuing a diagnostic message for an overfull or
underfull hbox\X\S$\6
\&{if} $\\{output\_active}$ \1\&{then}\5
$\\{print}(\.{")\ has\ occurred\ while\ \\output\ is\ active"})$\6
\4\&{else} \&{begin} \37\&{if} $\\{pack\_begin\_line}\I0$ \1\&{then}\6
\&{begin} \37\&{if} $\\{pack\_begin\_line}>0$ \1\&{then}\5
$\\{print}(\.{")\ in\ paragraph\ at\ lines\ "})$\6
\4\&{else} $\\{print}(\.{")\ in\ alignment\ at\ lines\ "})$;\2\6
$\\{print\_int}(\\{abs}(\\{pack\_begin\_line}))$;\5
$\\{print}(\.{"--"})$;\6
\&{end}\6
\4\&{else} $\\{print}(\.{")\ detected\ at\ line\ "})$;\2\6
$\\{print\_int}(\\{line})$;\6
\&{if} $\\{page}>1$ \1\&{then}\6
\&{begin} \37$\\{print}(\.{",\ p."})$;\5
$\\{print\_int}(\\{page})$;\6
\&{end};\2\6
\&{end};\2\6
\\{print\_ln};\6
$\\{font\_in\_short\_display}\K\\{null\_font}$;\5
$\\{short\_display}(\\{list\_ptr}(\|r))$;\5
\\{print\_ln};\6
\\{begin\_diagnostic};\5
$\\{show\_box}(\|r)$;\5
$\\{end\_diagnostic}(\\{true})$\par
\U section~649.\fi

\M664. \P$\X664:Determine horizontal glue shrink setting, then \&{return} or %
\hbox{\&{goto} \\{common\_ending}}\X\S$\6
\&{begin} \37\X665:Determine the shrink order\X;\6
$\\{glue\_order}(\|r)\K\|o$;\5
$\\{glue\_sign}(\|r)\K\\{shrinking}$;\6
\&{if} $\\{total\_shrink}[\|o]\I0$ \1\&{then}\5
$\\{glue\_set}(\|r)\K\\{unfloat}((-\|x)/\\{total\_shrink}[\|o])$\6
\4\&{else} \&{begin} \37$\\{glue\_sign}(\|r)\K\\{normal}$;\5
$\\{set\_glue\_ratio\_zero}(\\{glue\_set}(\|r))$;\C{there's nothing to shrink}\6
\&{end};\2\6
\&{if} $(\\{total\_shrink}[\|o]<-\|x)\W(\|o=\\{normal})\W(\\{list\_ptr}(\|r)\I%
\\{null})$ \1\&{then}\6
\&{begin} \37$\\{set\_glue\_ratio\_one}(\\{glue\_set}(\|r))$;\C{this is the
maximum shrinkage}\6
\X666:Report an overfull hbox and \&{goto} \\{common\_ending}, if this box is
sufficiently bad\X;\6
\&{end}\6
\4\&{else} \&{if} $(\\{hbadness}<100)\W(\|o=\\{normal})\W(\\{list\_ptr}(\|r)\I%
\\{null})$ \1\&{then}\5
\X667:Report a tight hbox and \&{goto} \\{common\_ending}, if this box is
sufficiently bad\X;\2\2\6
\&{return};\6
\&{end}\par
\U section~657.\fi

\M665. \P$\X665:Determine the shrink order\X\S$\6
\&{if} $\\{total\_shrink}[\\{filll}]\I0$ \1\&{then}\5
$\|o\K\\{filll}$\6
\4\&{else} \&{if} $\\{total\_shrink}[\\{fill}]\I0$ \1\&{then}\5
$\|o\K\\{fill}$\6
\4\&{else} \&{if} $\\{total\_shrink}[\\{fil}]\I0$ \1\&{then}\5
$\|o\K\\{fil}$\6
\4\&{else} $\|o\K\\{normal}$\2\2\2\par
\U sections~664, 676, and~796.\fi

\M666. \P$\X666:Report an overfull hbox and \&{goto} \\{common\_ending}, if
this box is sufficiently bad\X\S$\6
\&{if} $(-\|x-\\{total\_shrink}[\\{normal}]>\\{hfuzz})\V(\\{hbadness}<100)$ \1%
\&{then}\6
\&{begin} \37\&{if} $(\\{overfull\_rule}>0)\W(-\|x-\\{total\_shrink}[%
\\{normal}]>\\{hfuzz})$ \1\&{then}\6
\&{begin} \37\&{while} $\\{link}(\|q)\I\\{null}$ \1\&{do}\5
$\|q\K\\{link}(\|q)$;\2\6
$\\{link}(\|q)\K\\{new\_rule}$;\5
$\\{width}(\\{link}(\|q))\K\\{overfull\_rule}$;\6
\&{end};\2\6
\\{print\_ln};\5
$\\{print\_nl}(\.{"Overfull\ \\hbox\ ("})$;\5
$\\{print\_scaled}(-\|x-\\{total\_shrink}[\\{normal}])$;\5
$\\{print}(\.{"pt\ too\ wide"})$;\5
\&{goto} \37\\{common\_ending};\6
\&{end}\2\par
\U section~664.\fi

\M667. \P$\X667:Report a tight hbox and \&{goto} \\{common\_ending}, if this
box is sufficiently bad\X\S$\6
\&{begin} \37$\|b\K\\{badness}(-\|x,\39\\{total\_shrink}[\\{normal}])$;\6
\&{if} $\|b>\\{hbadness}$ \1\&{then}\6
\&{begin} \37\\{print\_ln};\5
$\\{print\_nl}(\.{"Tight\ \\hbox\ (badness\ "})$;\5
$\\{print\_int}(\|b)$;\5
\&{goto} \37\\{common\_ending};\6
\&{end};\2\6
\&{end}\par
\U section~664.\fi

\M668. The \\{vpack} subroutine is actually a special case of a slightly more
general routine called \\{vpackage}, which has four parameters. The fourth
parameter, which is \\{max\_dimen} in the case of \\{vpack}, specifies the
maximum depth of the page box that is constructed. The depth is first
computed by the normal rules; if it exceeds this limit, the reference
point is simply moved down until the limiting depth is attained.

\Y\P\D \37$\\{vpack}(\#)\S\\{vpackage}(\#,\39\\{max\_dimen})$\C{special case of
unconstrained depth}\par
\Y\P\4\&{function}\1\  \37$\\{vpackage}(\|p:\\{pointer};\,\35\|h:\\{scaled};\,%
\35\|m:\\{small\_number};\,\35\|l:\\{scaled})$: \37\\{pointer};\6
\4\&{label} \37$\\{common\_ending},\39\\{exit}$;\6
\4\&{var} \37\|r: \37\\{pointer};\C{the box node that will be returned}\6
$\|w,\39\|d,\39\|x$: \37\\{scaled};\C{width, depth, and natural height}\6
\|s: \37\\{scaled};\C{shift amount}\6
\|g: \37\\{pointer};\C{points to a glue specification}\6
\|o: \37\\{glue\_ord};\C{order of infinity}\6
\|b: \37\\{integer};\C{badness of the new box}\2\6
\&{begin} \37$\|r\K\\{get\_node}(\\{box\_node\_size})$;\5
$\\{type}(\|r)\K\\{vlist\_node}$;\5
$\\{subtype}(\|r)\K\\{min\_quarterword}$;\5
$\\{shift\_amount}(\|r)\K0$;\5
$\\{list\_ptr}(\|r)\K\|p$;\6
$\|w\K0$;\5
\X650:Clear dimensions to zero\X;\6
\&{while} $\|p\I\\{null}$ \1\&{do}\5
\X669:Examine node \|p in the vlist, taking account of its effect on the
dimensions of the new box; then advance \|p to the next node\X;\2\6
$\\{width}(\|r)\K\|w$;\6
\&{if} $\|d>\|l$ \1\&{then}\6
\&{begin} \37$\|x\K\|x+\|d-\|l$;\5
$\\{depth}(\|r)\K\|l$;\6
\&{end}\6
\4\&{else} $\\{depth}(\|r)\K\|d$;\2\6
\X672:Determine the value of $\\{height}(\|r)$ and the appropriate glue
setting; then \&{return} or \&{goto} \\{common\_ending}\X;\6
\4\\{common\_ending}: \37\X675\*:Finish issuing a diagnostic message for an
overfull or underfull vbox\X;\6
\4\\{exit}: \37$\\{vpackage}\K\|r$;\6
\&{end};\par
\fi

\M669. \P$\X669:Examine node \|p in the vlist, taking account of its effect on
the dimensions of the new box; then advance \|p to the next node\X\S$\6
\&{begin} \37\&{if} $\\{is\_char\_node}(\|p)$ \1\&{then}\5
$\\{confusion}(\.{"vpack"})$\6
\4\&{else} \&{case} $\\{type}(\|p)$ \1\&{of}\6
\4$\\{hlist\_node},\39\\{vlist\_node},\39\\{rule\_node},\39\\{unset\_node}$: %
\37\X670:Incorporate box dimensions into the dimensions of the vbox that will
contain~it\X;\6
\4\\{whatsit\_node}: \37\X1359:Incorporate a whatsit node into a vbox\X;\6
\4\\{glue\_node}: \37\X671:Incorporate glue into the vertical totals\X;\6
\4\\{kern\_node}: \37\&{begin} \37$\|x\K\|x+\|d+\\{width}(\|p)$;\5
$\|d\K0$;\6
\&{end};\6
\4\&{othercases} \37\\{do\_nothing}\2\6
\&{endcases};\2\6
$\|p\K\\{link}(\|p)$;\6
\&{end}\par
\U section~668.\fi

\M670. \P$\X670:Incorporate box dimensions into the dimensions of the vbox that
will contain~it\X\S$\6
\&{begin} \37$\|x\K\|x+\|d+\\{height}(\|p)$;\5
$\|d\K\\{depth}(\|p)$;\6
\&{if} $\\{type}(\|p)\G\\{rule\_node}$ \1\&{then}\5
$\|s\K0$\ \&{else} $\|s\K\\{shift\_amount}(\|p)$;\2\6
\&{if} $\\{width}(\|p)+\|s>\|w$ \1\&{then}\5
$\|w\K\\{width}(\|p)+\|s$;\2\6
\&{end}\par
\U section~669.\fi

\M671. \P$\X671:Incorporate glue into the vertical totals\X\S$\6
\&{begin} \37$\|x\K\|x+\|d$;\5
$\|d\K0$;\6
$\|g\K\\{glue\_ptr}(\|p)$;\5
$\|x\K\|x+\\{width}(\|g)$;\6
$\|o\K\\{stretch\_order}(\|g)$;\5
$\\{total\_stretch}[\|o]\K\\{total\_stretch}[\|o]+\\{stretch}(\|g)$;\5
$\|o\K\\{shrink\_order}(\|g)$;\5
$\\{total\_shrink}[\|o]\K\\{total\_shrink}[\|o]+\\{shrink}(\|g)$;\6
\&{if} $\\{subtype}(\|p)\G\\{a\_leaders}$ \1\&{then}\6
\&{begin} \37$\|g\K\\{leader\_ptr}(\|p)$;\6
\&{if} $\\{width}(\|g)>\|w$ \1\&{then}\5
$\|w\K\\{width}(\|g)$;\2\6
\&{end};\2\6
\&{end}\par
\U section~669.\fi

\M672. When we get to the present part of the program, \|x is the natural
height
of the box being packaged.

\Y\P$\4\X672:Determine the value of $\\{height}(\|r)$ and the appropriate glue
setting; then \&{return} or \&{goto} \\{common\_ending}\X\S$\6
\&{if} $\|m=\\{additional}$ \1\&{then}\5
$\|h\K\|x+\|h$;\2\6
$\\{height}(\|r)\K\|h$;\5
$\|x\K\|h-\|x$;\C{now \|x is the excess to be made up}\6
\&{if} $\|x=0$ \1\&{then}\6
\&{begin} \37$\\{glue\_sign}(\|r)\K\\{normal}$;\5
$\\{glue\_order}(\|r)\K\\{normal}$;\5
$\\{set\_glue\_ratio\_zero}(\\{glue\_set}(\|r))$;\5
\&{return};\6
\&{end}\6
\4\&{else} \&{if} $\|x>0$ \1\&{then}\5
\X673:Determine vertical glue stretch setting, then \&{return} or \hbox{%
\&{goto} \\{common\_ending}}\X\6
\4\&{else} \X676:Determine vertical glue shrink setting, then \&{return} or %
\hbox{\&{goto} \\{common\_ending}}\X\2\2\par
\U section~668.\fi

\M673. \P$\X673:Determine vertical glue stretch setting, then \&{return} or %
\hbox{\&{goto} \\{common\_ending}}\X\S$\6
\&{begin} \37\X659:Determine the stretch order\X;\6
$\\{glue\_order}(\|r)\K\|o$;\5
$\\{glue\_sign}(\|r)\K\\{stretching}$;\6
\&{if} $\\{total\_stretch}[\|o]\I0$ \1\&{then}\5
$\\{glue\_set}(\|r)\K\\{unfloat}(\|x/\\{total\_stretch}[\|o])$\6
\4\&{else} \&{begin} \37$\\{glue\_sign}(\|r)\K\\{normal}$;\5
$\\{set\_glue\_ratio\_zero}(\\{glue\_set}(\|r))$;\C{there's nothing to stretch}%
\6
\&{end};\2\6
\&{if} $(\\{vbadness}<\\{inf\_bad})\W(\|o=\\{normal})\W(\\{list\_ptr}(\|r)\I%
\\{null})$ \1\&{then}\5
\X674:Report an underfull vbox and \&{goto} \\{common\_ending}, if this box is
sufficiently bad\X;\2\6
\&{return};\6
\&{end}\par
\U section~672.\fi

\M674. \P$\X674:Report an underfull vbox and \&{goto} \\{common\_ending}, if
this box is sufficiently bad\X\S$\6
\&{begin} \37$\|b\K\\{badness}(\|x,\39\\{total\_stretch}[\\{normal}])$;\6
\&{if} $\|b>\\{vbadness}$ \1\&{then}\6
\&{begin} \37\\{print\_ln};\6
\&{if} $\|b>100$ \1\&{then}\5
$\\{print\_nl}(\.{"Underfull"})$\ \&{else} $\\{print\_nl}(\.{"Loose"})$;\2\6
$\\{print}(\.{"\ \\vbox\ (badness\ "})$;\5
$\\{print\_int}(\|b)$;\5
\&{goto} \37\\{common\_ending};\6
\&{end};\2\6
\&{end}\par
\U section~673.\fi

\M675\*. \P$\X675\*:Finish issuing a diagnostic message for an overfull or
underfull vbox\X\S$\6
\&{if} $\\{output\_active}$ \1\&{then}\5
$\\{print}(\.{")\ has\ occurred\ while\ \\output\ is\ active"})$\6
\4\&{else} \&{begin} \37\&{if} $\\{pack\_begin\_line}\I0$ \1\&{then}\C{it's
actually negative}\6
\&{begin} \37$\\{print}(\.{")\ in\ alignment\ at\ lines\ "})$;\5
$\\{print\_int}(\\{abs}(\\{pack\_begin\_line}))$;\5
$\\{print}(\.{"--"})$;\6
\&{end}\6
\4\&{else} $\\{print}(\.{")\ detected\ at\ line\ "})$;\2\6
$\\{print\_int}(\\{line})$;\6
\&{if} $\\{page}>1$ \1\&{then}\6
\&{begin} \37$\\{print}(\.{",\ p."})$;\5
$\\{print\_int}(\\{page})$;\6
\&{end};\2\6
\\{print\_ln};\6
\&{end};\2\6
\\{begin\_diagnostic};\5
$\\{show\_box}(\|r)$;\5
$\\{end\_diagnostic}(\\{true})$\par
\U section~668.\fi

\M676. \P$\X676:Determine vertical glue shrink setting, then \&{return} or %
\hbox{\&{goto} \\{common\_ending}}\X\S$\6
\&{begin} \37\X665:Determine the shrink order\X;\6
$\\{glue\_order}(\|r)\K\|o$;\5
$\\{glue\_sign}(\|r)\K\\{shrinking}$;\6
\&{if} $\\{total\_shrink}[\|o]\I0$ \1\&{then}\5
$\\{glue\_set}(\|r)\K\\{unfloat}((-\|x)/\\{total\_shrink}[\|o])$\6
\4\&{else} \&{begin} \37$\\{glue\_sign}(\|r)\K\\{normal}$;\5
$\\{set\_glue\_ratio\_zero}(\\{glue\_set}(\|r))$;\C{there's nothing to shrink}\6
\&{end};\2\6
\&{if} $(\\{total\_shrink}[\|o]<-\|x)\W(\|o=\\{normal})\W(\\{list\_ptr}(\|r)\I%
\\{null})$ \1\&{then}\6
\&{begin} \37$\\{set\_glue\_ratio\_one}(\\{glue\_set}(\|r))$;\C{this is the
maximum shrinkage}\6
\X677:Report an overfull vbox and \&{goto} \\{common\_ending}, if this box is
sufficiently bad\X;\6
\&{end}\6
\4\&{else} \&{if} $(\\{vbadness}<100)\W(\|o=\\{normal})\W(\\{list\_ptr}(\|r)\I%
\\{null})$ \1\&{then}\5
\X678:Report a tight vbox and \&{goto} \\{common\_ending}, if this box is
sufficiently bad\X;\2\2\6
\&{return};\6
\&{end}\par
\U section~672.\fi

\M677. \P$\X677:Report an overfull vbox and \&{goto} \\{common\_ending}, if
this box is sufficiently bad\X\S$\6
\&{if} $(-\|x-\\{total\_shrink}[\\{normal}]>\\{vfuzz})\V(\\{vbadness}<100)$ \1%
\&{then}\6
\&{begin} \37\\{print\_ln};\5
$\\{print\_nl}(\.{"Overfull\ \\vbox\ ("})$;\5
$\\{print\_scaled}(-\|x-\\{total\_shrink}[\\{normal}])$;\5
$\\{print}(\.{"pt\ too\ high"})$;\5
\&{goto} \37\\{common\_ending};\6
\&{end}\2\par
\U section~676.\fi

\M678. \P$\X678:Report a tight vbox and \&{goto} \\{common\_ending}, if this
box is sufficiently bad\X\S$\6
\&{begin} \37$\|b\K\\{badness}(-\|x,\39\\{total\_shrink}[\\{normal}])$;\6
\&{if} $\|b>\\{vbadness}$ \1\&{then}\6
\&{begin} \37\\{print\_ln};\5
$\\{print\_nl}(\.{"Tight\ \\vbox\ (badness\ "})$;\5
$\\{print\_int}(\|b)$;\5
\&{goto} \37\\{common\_ending};\6
\&{end};\2\6
\&{end}\par
\U section~676.\fi

\M679. When a box is being appended to the current vertical list, the
baselineskip calculation is handled by the \\{append\_to\_vlist} routine.

\Y\P\4\&{procedure}\1\  \37$\\{append\_to\_vlist}(\|b:\\{pointer})$;\6
\4\&{var} \37\|d: \37\\{scaled};\C{deficiency of space between baselines}\6
\|p: \37\\{pointer};\C{a new glue specification}\2\6
\&{begin} \37\&{if} $\\{prev\_depth}>\\{ignore\_depth}$ \1\&{then}\6
\&{begin} \37$\|d\K\\{width}(\\{baseline\_skip})-\\{prev\_depth}-\\{height}(%
\|b)$;\6
\&{if} $\|d<\\{line\_skip\_limit}$ \1\&{then}\5
$\|p\K\\{new\_param\_glue}(\\{line\_skip\_code})$\6
\4\&{else} \&{begin} \37$\|p\K\\{new\_skip\_param}(\\{baseline\_skip\_code})$;\5
$\\{width}(\\{temp\_ptr})\K\|d$;\C{$\\{temp\_ptr}=\\{glue\_ptr}(\|p)$}\6
\&{end};\2\6
$\\{link}(\\{tail})\K\|p$;\5
$\\{tail}\K\|p$;\6
\&{end};\2\6
$\\{link}(\\{tail})\K\|b$;\5
$\\{tail}\K\|b$;\5
$\\{prev\_depth}\K\\{depth}(\|b)$;\6
\&{end};\par
\fi

\N680.  \[34] Data structures for math mode.
When \TeX\ reads a formula that is enclosed between \.\$'s, it constructs an
{\sl mlist}, which is essentially a tree structure representing that
formula.  An mlist is a linear sequence of items, but we can regard it as
a tree structure because mlists can appear within mlists. For example, many
of the entries can be subscripted or superscripted, and such ``scripts''
are mlists in their own right.

An entire formula is parsed into such a tree before any of the actual
typesetting is done, because the current style of type is usually not
known until the formula has been fully scanned. For example, when the
formula `\.{\$a+b \\over c+d\$}' is being read, there is no way to tell
that `\.{a+b}' will be in script size until `\.{\\over}' has appeared.

During the scanning process, each element of the mlist being built is
classified as a relation, a binary operator, an open parenthesis, etc.,
or as a construct like `\.{\\sqrt}' that must be built up. This classification
appears in the mlist data structure.

After a formula has been fully scanned, the mlist is converted to an hlist
so that it can be incorporated into the surrounding text. This conversion is
controlled by a recursive procedure that decides all of the appropriate
styles by a ``top-down'' process starting at the outermost level and working
in towards the subformulas. The formula is ultimately pasted together using
combinations of horizontal and vertical boxes, with glue and penalty nodes
inserted as necessary.

An mlist is represented internally as a linked list consisting chiefly
of ``noads'' (pronounced ``no-adds''), to distinguish them from the somewhat
similar ``nodes'' in hlists and vlists. Certain kinds of ordinary nodes are
allowed to appear in mlists together with the noads; \TeX\ tells the difference
by means of the \\{type} field, since a noad's \\{type} is always greater than
that of a node. An mlist does not contain character nodes, hlist nodes, vlist
nodes, math nodes, ligature nodes, mark nodes, insert nodes, adjust nodes,
or unset nodes; in particular, each mlist item appears in the
variable-size part of \\{mem}, so the \\{type} field is always present.

\fi

\M681. Each noad is four or more words long. The first word contains the %
\\{type}
and \\{subtype} and \\{link} fields that are already so familiar to us; the
second, third, and fourth words are called the noad's \\{nucleus}, \\{subscr},
and \\{supscr} fields.

Consider, for example, the simple formula `\.{\$x\↑2\$}', which would be
parsed into an mlist containing a single element called an \\{ord\_noad}.
The \\{nucleus} of this noad is a representation of `\.x', the \\{subscr} is
empty, and the \\{supscr} is a representation of `\.2'.

The \\{nucleus}, \\{subscr}, and \\{supscr} fields are further broken into
subfields. If \|p points to a noad, and if \|q is one of its principal
fields (e.g., $\|q=\\{subscr}(\|p)$), there are several possibilities for the
subfields, depending on the \\{math\_type} of \|q.

\yskip\hang$\\{math\_type}(\|q)=\\{math\_char}$ means that $\\{fam}(\|q)$
refers to one of
the sixteen font families, and $\\{character}(\|q)$ is the number of a
character
within a font of that family, as in a character node.

\yskip\hang$\\{math\_type}(\|q)=\\{math\_text\_char}$ is similar, but the
character is
unsubscripted and unsuperscripted and it is followed immediately by another
character from the same font. (This \\{math\_type} setting appears only
briefly during the processing; it is used to suppress unwanted italic
corrections.)

\yskip\hang$\\{math\_type}(\|q)=\\{empty}$ indicates a field with no value (the
corresponding attribute of noad \|p is not present).

\yskip\hang$\\{math\_type}(\|q)=\\{sub\_box}$ means that $\\{info}(\|q)$ points
to a box
node (either an \\{hlist\_node} or a \\{vlist\_node}) that should be used as
the
value of the field.  The \\{shift\_amount} in the subsidiary box node is the
amount by which that box will be shifted downward.

\yskip\hang$\\{math\_type}(\|q)=\\{sub\_mlist}$ means that $\\{info}(\|q)$
points to
an mlist; the mlist must be converted to an hlist in order to obtain
the value of this field.

\yskip\noindent In the latter case, we might have $\\{info}(\|q)=\\{null}$.
This
is not the same as $\\{math\_type}(\|q)=\\{empty}$; for example, `\.{\$P\_\{\}%
\$}'
and `\.{\$P\$}' produce different results (the former will not have the
``italic correction'' added to the width of \|P, but the ``script skip''
will be added).

The definitions of subfields given here are evidently wasteful of space,
since a halfword is being used for the \\{math\_type} although only three
bits would be needed. However, there are hardly ever many noads present at
once, since they are soon converted to nodes that take up even more space,
so we can afford to represent them in whatever way simplifies the
programming.

\Y\P\D \37$\\{noad\_size}=4$\C{number of words in a normal noad}\par
\P\D \37$\\{nucleus}(\#)\S\#+1$\C{the \\{nucleus} field of a noad}\par
\P\D \37$\\{supscr}(\#)\S\#+2$\C{the \\{supscr} field of a noad}\par
\P\D \37$\\{subscr}(\#)\S\#+3$\C{the \\{subscr} field of a noad}\par
\P\D \37$\\{math\_type}\S\\{link}$\C{a \\{halfword} in \\{mem}}\par
\P\D \37$\\{fam}\S\\{font}$\C{a \\{quarterword} in \\{mem}}\par
\P\D \37$\\{math\_char}=1$\C{\\{math\_type} when the attribute is simple}\par
\P\D \37$\\{sub\_box}=2$\C{\\{math\_type} when the attribute is a box}\par
\P\D \37$\\{sub\_mlist}=3$\C{\\{math\_type} when the attribute is a formula}\par
\P\D \37$\\{math\_text\_char}=4$\C{\\{math\_type} when italic correction is
dubious}\par
\fi

\M682. Each portion of a formula is classified as Ord, Op, Bin, Rel, Ope,
Clo, Pun, or Inn, for purposes of spacing and line breaking. An
\\{ord\_noad}, \\{op\_noad}, \\{bin\_noad}, \\{rel\_noad}, \\{open\_noad}, %
\\{close\_noad},
\\{punct\_noad}, or \\{inner\_noad} is used to represent portions of the
various
types. For example, an `\.=' sign in a formula leads to the creation of a
\\{rel\_noad} whose \\{nucleus} field is a representation of an equals sign
(usually $\\{fam}=0$, $\\{character}=\O{75}$).  A formula preceded by \.{%
\\mathrel}
also results in a \\{rel\_noad}.  When a \\{rel\_noad} is followed by an
\\{op\_noad}, say, and possibly separated by one or more ordinary nodes (not
noads), \TeX\ will insert a penalty node (with the current \\{rel\_penalty})
just after the formula that corresponds to the \\{rel\_noad}, unless there
already was a penalty immediately following; and a ``thick space'' will be
inserted just before the formula that corresponds to the \\{op\_noad}.

A noad of type \\{ord\_noad}, \\{op\_noad}, \dots, \\{inner\_noad} usually
has a $\\{subtype}=\\{normal}$. The only exception is that an \\{op\_noad}
might
have $\\{subtype}=\\{limits}$ or \\{no\_limits}, if the normal positioning of
limits has been overridden for this operator.

\Y\P\D \37$\\{ord\_noad}=\\{unset\_node}+3$\C{\\{type} of a noad classified
Ord}\par
\P\D \37$\\{op\_noad}=\\{ord\_noad}+1$\C{\\{type} of a noad classified Op}\par
\P\D \37$\\{bin\_noad}=\\{ord\_noad}+2$\C{\\{type} of a noad classified Bin}\par
\P\D \37$\\{rel\_noad}=\\{ord\_noad}+3$\C{\\{type} of a noad classified Rel}\par
\P\D \37$\\{open\_noad}=\\{ord\_noad}+4$\C{\\{type} of a noad classified Ope}%
\par
\P\D \37$\\{close\_noad}=\\{ord\_noad}+5$\C{\\{type} of a noad classified Clo}%
\par
\P\D \37$\\{punct\_noad}=\\{ord\_noad}+6$\C{\\{type} of a noad classified Pun}%
\par
\P\D \37$\\{inner\_noad}=\\{ord\_noad}+7$\C{\\{type} of a noad classified Inn}%
\par
\P\D \37$\\{limits}=1$\C{\\{subtype} of \\{op\_noad} whose scripts are to be
above, below}\par
\P\D \37$\\{no\_limits}=2$\C{\\{subtype} of \\{op\_noad} whose scripts are to
be normal}\par
\fi

\M683. A \\{radical\_noad} is five words long; the fifth word is the \\{left%
\_delimiter}
field, which usually represents a square root sign.

A \\{fraction\_noad} is six words long; it has a \\{right\_delimiter} field
as well as a \\{left\_delimiter}.

Delimiter fields are of type \\{four\_quarters}, and they have four subfields
called \\{small\_fam}, \\{small\_char}, \\{large\_fam}, \\{large\_char}. These
subfields
represent variable-size delimiters by giving the ``small'' and ``large''
starting characters, as explained in Chapter~17 of {\sl The \TeX book}.

A \\{fraction\_noad} is actually quite different from all other noads. Not
only does it have six words, it has \\{thickness}, \\{denominator}, and
\\{numerator} fields instead of \\{nucleus}, \\{subscr}, and \\{supscr}. The
\\{thickness} is a scaled value that tells how thick to make a fraction
rule; however, the special value \\{default\_code} is used to stand for the
\\{default\_rule\_thickness} of the current size. The \\{numerator} and
\\{denominator} point to mlists that define a fraction; we always have
$$\hbox{$\\{math\_type}(\\{numerator})=\\{math\_type}(\\{denominator})=\\{sub%
\_mlist}$}.$$ The
\\{left\_delimiter} and \\{right\_delimiter} fields specify delimiters that
will
be placed at the left and right of the fraction. In this way, a
\\{fraction\_noad} is able to represent all of \TeX's operators \.{\\over},
\.{\\atop}, \.{\\above}, \.{\\overwithdelims}, \.{\\atopwithdelims}, and
\.{\\abovewithdelims}.

\Y\P\D \37$\\{left\_delimiter}(\#)\S\#+4$\C{first delimiter field of a noad}\par
\P\D \37$\\{right\_delimiter}(\#)\S\#+5$\C{second delimiter field of a fraction
noad}\par
\P\D \37$\\{radical\_noad}=\\{inner\_noad}+1$\C{\\{type} of a noad for square
roots}\par
\P\D \37$\\{radical\_noad\_size}=5$\C{number of \\{mem} words in a radical
noad}\par
\P\D \37$\\{fraction\_noad}=\\{radical\_noad}+1$\C{\\{type} of a noad for
generalized fractions}\par
\P\D \37$\\{fraction\_noad\_size}=6$\C{number of \\{mem} words in a fraction
noad}\par
\P\D \37$\\{small\_fam}(\#)\S\\{mem}[\#].\\{qqqq}.\\{b0}$\C{\\{fam} for
``small'' delimiter}\par
\P\D \37$\\{small\_char}(\#)\S\\{mem}[\#].\\{qqqq}.\\{b1}$\C{\\{character} for
``small'' delimiter}\par
\P\D \37$\\{large\_fam}(\#)\S\\{mem}[\#].\\{qqqq}.\\{b2}$\C{\\{fam} for
``large'' delimiter}\par
\P\D \37$\\{large\_char}(\#)\S\\{mem}[\#].\\{qqqq}.\\{b3}$\C{\\{character} for
``large'' delimiter}\par
\P\D \37$\\{thickness}\S\\{width}$\C{\\{thickness} field in a fraction noad}\par
\P\D \37$\\{default\_code}\S\O{10000000000}$\C{denotes \\{default\_rule%
\_thickness}}\par
\P\D \37$\\{numerator}\S\\{supscr}$\C{\\{numerator} field in a fraction noad}%
\par
\P\D \37$\\{denominator}\S\\{subscr}$\C{\\{denominator} field in a fraction
noad}\par
\fi

\M684. The global variable \\{empty\_field} is set up for initialization of
empty
fields in new noads. Similarly, \\{null\_delimiter} is for the initialization
of delimiter fields.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{empty\_field}: \37\\{two\_halves};\6
\4\\{null\_delimiter}: \37\\{four\_quarters};\par
\fi

\M685. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{empty\_field}.\\{rh}\K\\{empty}$;\5
$\\{empty\_field}.\\{lh}\K\\{null}$;\6
$\\{null\_delimiter}.\\{b0}\K0$;\5
$\\{null\_delimiter}.\\{b1}\K\\{min\_quarterword}$;\6
$\\{null\_delimiter}.\\{b2}\K0$;\5
$\\{null\_delimiter}.\\{b3}\K\\{min\_quarterword}$;\par
\fi

\M686. The \\{new\_noad} function creates an \\{ord\_noad} that is completely
null.

\Y\P\4\&{function}\1\  \37\\{new\_noad}: \37\\{pointer};\6
\4\&{var} \37\|p: \37\\{pointer};\2\6
\&{begin} \37$\|p\K\\{get\_node}(\\{noad\_size})$;\5
$\\{type}(\|p)\K\\{ord\_noad}$;\5
$\\{subtype}(\|p)\K\\{normal}$;\5
$\\{mem}[\\{nucleus}(\|p)].\\{hh}\K\\{empty\_field}$;\5
$\\{mem}[\\{subscr}(\|p)].\\{hh}\K\\{empty\_field}$;\5
$\\{mem}[\\{supscr}(\|p)].\\{hh}\K\\{empty\_field}$;\5
$\\{new\_noad}\K\|p$;\6
\&{end};\par
\fi

\M687. A few more kinds of noads will complete the set: An \\{under\_noad} has
its
nucleus underlined; an \\{over\_noad} has it overlined. An \\{accent\_noad}
places
an accent over its nucleus; the accent character appears as
$\\{fam}(\\{accent\_chr}(\|p))$ and $\\{character}(\\{accent\_chr}(\|p))$. A %
\\{vcenter\_noad}
centers its nucleus vertically with respect to the axis of the formula;
we always have $\\{math\_type}(\\{nucleus}(\|p))=\\{sub\_box}$ in this case.

And finally, we have \\{left\_noad} and \\{right\_noad} types, to implement
\TeX's \.{\\left} and \.{\\right}. The \\{nucleus} of such noads is
replaced by a \\{delimiter} field; thus, for example, `\.{\\left(}' produces
a \\{left\_noad} such that $\\{delimiter}(\|p)$ holds the family and character
codes for all left parentheses. A \\{left\_noad} never appears in an mlist
except as the first element, and a \\{right\_noad} never appears in an mlist
except as the last element; furthermore, we either have both a \\{left\_noad}
and a \\{right\_noad}, or neither one is present. The \\{subscr} and \\{supscr}
fields are always \\{empty} in a \\{left\_noad} and a \\{right\_noad}.

\Y\P\D \37$\\{under\_noad}=\\{fraction\_noad}+1$\C{\\{type} of a noad for
underlining}\par
\P\D \37$\\{over\_noad}=\\{under\_noad}+1$\C{\\{type} of a noad for overlining}%
\par
\P\D \37$\\{accent\_noad}=\\{over\_noad}+1$\C{\\{type} of a noad for accented
subformulas}\par
\P\D \37$\\{accent\_noad\_size}=5$\C{number of \\{mem} words in an accent noad}%
\par
\P\D \37$\\{accent\_chr}(\#)\S\#+4$\C{the \\{accent\_chr} field of an accent
noad}\par
\P\D \37$\\{vcenter\_noad}=\\{accent\_noad}+1$\C{\\{type} of a noad for \.{%
\\vcenter}}\par
\P\D \37$\\{left\_noad}=\\{vcenter\_noad}+1$\C{\\{type} of a noad for \.{%
\\left}}\par
\P\D \37$\\{right\_noad}=\\{left\_noad}+1$\C{\\{type} of a noad for \.{%
\\right}}\par
\P\D \37$\\{delimiter}\S\\{nucleus}$\C{\\{delimiter} field in left and right
noads}\par
\P\D \37$\\{scripts\_allowed}(\#)\S(\\{type}(\#)\G\\{ord\_noad})\W(\\{type}(%
\#)<\\{left\_noad})$\par
\fi

\M688. Math formulas can also contain instructions like \.{\\textstyle} that
override \TeX's normal style rules. A \\{style\_node} is inserted into the
data structure to record such instructions; it is three words long, so it
is considered a node instead of a noad. The \\{subtype} is either \\{display%
\_style}
or \\{text\_style} or \\{script\_style} or \\{script\_script\_style}. The
second and third words of a \\{style\_node} are not used, but they are
present because a \\{choice\_node} is converted to a \\{style\_node}.

\TeX\ uses even numbers 0, 2, 4, 6 to encode the basic styles
\\{display\_style}, \dots, \\{script\_script\_style}, and adds~1 to get the
``cramped'' versions of these styles. This gives a numerical order that
is backwards from the convention of Appendix~G in {\sl The \TeX book\/};
i.e., a smaller style has a larger numerical value.

\Y\P\D \37$\\{style\_node}=\\{unset\_node}+1$\C{\\{type} of a style node}\par
\P\D \37$\\{style\_node\_size}=3$\C{number of words in a style node}\par
\P\D \37$\\{display\_style}=0$\C{\\{subtype} for \.{\\displaystyle}}\par
\P\D \37$\\{text\_style}=2$\C{\\{subtype} for \.{\\textstyle}}\par
\P\D \37$\\{script\_style}=4$\C{\\{subtype} for \.{\\scriptstyle}}\par
\P\D \37$\\{script\_script\_style}=6$\C{\\{subtype} for \.{%
\\scriptscriptstyle}}\par
\P\D \37$\\{cramped}=1$\C{add this to an uncramped style if you want to cramp
it}\par
\Y\P\4\&{function}\1\  \37$\\{new\_style}(\|s:\\{small\_number})$: \37%
\\{pointer};\C{create a style node}\6
\4\&{var} \37\|p: \37\\{pointer};\C{the new node}\2\6
\&{begin} \37$\|p\K\\{get\_node}(\\{style\_node\_size})$;\5
$\\{type}(\|p)\K\\{style\_node}$;\5
$\\{subtype}(\|p)\K\|s$;\5
$\\{width}(\|p)\K0$;\5
$\\{depth}(\|p)\K0$;\C{the \\{width} and \\{depth} are not used}\6
$\\{new\_style}\K\|p$;\6
\&{end};\par
\fi

\M689. Finally, the \.{\\mathchoice} primitive creates a \\{choice\_node},
which
has special subfields \\{display\_mlist}, \\{text\_mlist}, \\{script\_mlist},
and \\{script\_script\_mlist} pointing to the mlists for each style.

\Y\P\D \37$\\{choice\_node}=\\{unset\_node}+2$\C{\\{type} of a choice node}\par
\P\D \37$\\{display\_mlist}(\#)\S\\{info}(\#+1)$\C{mlist to be used in display
style}\par
\P\D \37$\\{text\_mlist}(\#)\S\\{link}(\#+1)$\C{mlist to be used in text style}%
\par
\P\D \37$\\{script\_mlist}(\#)\S\\{info}(\#+2)$\C{mlist to be used in script
style}\par
\P\D \37$\\{script\_script\_mlist}(\#)\S\\{link}(\#+2)$\C{mlist to be used in
scriptscript style}\par
\Y\P\4\&{function}\1\  \37\\{new\_choice}: \37\\{pointer};\C{create a choice
node}\6
\4\&{var} \37\|p: \37\\{pointer};\C{the new node}\2\6
\&{begin} \37$\|p\K\\{get\_node}(\\{style\_node\_size})$;\5
$\\{type}(\|p)\K\\{choice\_node}$;\5
$\\{subtype}(\|p)\K0$;\C{the \\{subtype} is not used}\6
$\\{display\_mlist}(\|p)\K\\{null}$;\5
$\\{text\_mlist}(\|p)\K\\{null}$;\5
$\\{script\_mlist}(\|p)\K\\{null}$;\5
$\\{script\_script\_mlist}(\|p)\K\\{null}$;\5
$\\{new\_choice}\K\|p$;\6
\&{end};\par
\fi

\M690. Let's consider now the previously unwritten part of \\{show\_node\_list}
that displays the things that can only be present in mlists; this
program illustrates how to access the data structures just defined.

In the context of the following program, \|p points to a node or noad that
should be displayed, and the current string contains the ``recursion history''
that leads to this point. The recursion history consists of a dot for each
outer level in which \|p is subsidiary to some node, or in which \|p is
subsidiary to the \\{nucleus} field of some noad; the dot is replaced by
`\.[' or `\.(' or `\./' or `\.\\' if \|p is descended from the \\{subscr}
or \\{supscr} or \\{denominator} or \\{numerator} fields of noads. For example,
the current string would be `\.{.\↑.\_/}' if \|p points to the \\{ord\_noad}
for
\|x in the (ridiculous) formula
`\.{\$\\sqrt\{a\↑\{\\mathinner\{b\_\{c\\over x+y\}\}\}\}\$}'.

\Y\P$\4\X690:Cases of \\{show\_node\_list} that arise in mlists only\X\S$\6
\4\\{style\_node}: \37$\\{print\_style}(\\{subtype}(\|p))$;\6
\4\\{choice\_node}: \37\X695:Display choice node \|p\X;\6
\4$\\{ord\_noad},\39\\{op\_noad},\39\\{bin\_noad},\39\\{rel\_noad},\39\\{open%
\_noad},\39\\{close\_noad},\39\\{punct\_noad},\39\\{inner\_noad},\39\\{radical%
\_noad},\39\\{over\_noad},\39\\{under\_noad},\39\\{vcenter\_noad},\39\\{accent%
\_noad},\39\\{left\_noad},\39\\{right\_noad}$: \37\X696:Display normal noad \|p%
\X;\6
\4\\{fraction\_noad}: \37\X697:Display fraction noad \|p\X;\par
\U section~183\*.\fi

\M691. Here are some simple routines used in the display of noads.

\Y\P$\4\X691:Declare procedures needed for displaying the elements of mlists\X%
\S$\6
\4\&{procedure}\1\  \37$\\{print\_fam\_and\_char}(\|p:\\{pointer})$;\C{prints
family and character}\2\6
\&{begin} \37$\\{print\_esc}(\.{"fam"})$;\5
$\\{print\_int}(\\{fam}(\|p))$;\5
$\\{print\_char}(\.{"\ "})$;\5
$\\{print\_ASCII}(\\{qo}(\\{character}(\|p)))$;\6
\&{end};\7
\4\&{procedure}\1\  \37$\\{print\_delimiter}(\|p:\\{pointer})$;\C{prints a
delimiter as 24-bit hex value}\6
\4\&{var} \37\|a: \37\\{integer};\C{accumulator}\2\6
\&{begin} \37$\|a\K\\{small\_fam}(\|p)\ast256+\\{qo}(\\{small\_char}(\|p))$;\5
$\|a\K\|a\ast\H{1000}+\\{large\_fam}(\|p)\ast256+\\{qo}(\\{large\_char}(\|p))$;%
\6
\&{if} $\|a<0$ \1\&{then}\5
$\\{print\_int}(\|a)$\C{this should never happen}\6
\4\&{else} $\\{print\_hex}(\|a)$;\2\6
\&{end};\par
\A sections~692 and~694.
\U section~179.\fi

\M692. The next subroutine will descend to another level of recursion when a
subsidiary mlist needs to be displayed. The parameter \|c indicates what
character is to become part of the recursion history. An empty mlist is
distinguished from a field with $\\{math\_type}(\|p)=\\{empty}$, because these
are
not equivalent (as explained above).

\Y\P$\4\X691:Declare procedures needed for displaying the elements of mlists\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{show\_info};\5
\\{forward};\5
\hbox{\2}\C{$\\{show\_node\_list}(\\{info}(\\{temp\_ptr}))$}\6
\4\&{procedure}\1\  \37$\\{print\_subsidiary\_data}(\|p:\\{pointer};\,\35\|c:%
\\{ASCII\_code})$;\C{display a noad field}\2\6
\&{begin} \37\&{if} $\\{cur\_length}\G\\{depth\_threshold}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{math\_type}(\|p)\I\\{empty}$ \1\&{then}\5
$\\{print}(\.{"\ []"})$;\2\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{append\_char}(\|c)$;\C{include \|c in the recursion
history}\6
$\\{temp\_ptr}\K\|p$;\C{prepare for \\{show\_info} if recursion is needed}\6
\&{case} $\\{math\_type}(\|p)$ \1\&{of}\6
\4\\{math\_char}: \37\&{begin} \37\\{print\_ln};\5
\\{print\_current\_string};\5
$\\{print\_fam\_and\_char}(\|p)$;\6
\&{end};\6
\4\\{sub\_box}: \37\\{show\_info};\C{recursive call}\6
\4\\{sub\_mlist}: \37\&{if} $\\{info}(\|p)=\\{null}$ \1\&{then}\6
\&{begin} \37\\{print\_ln};\5
\\{print\_current\_string};\5
$\\{print}(\.{"\{\}"})$;\6
\&{end}\6
\4\&{else} \\{show\_info};\C{recursive call}\2\6
\4\&{othercases} \37\\{do\_nothing}\C{\\{empty}}\2\6
\&{endcases};\6
\\{flush\_char};\C{remove \|c from the recursion history}\6
\&{end};\2\6
\&{end};\par
\fi

\M693. The inelegant introduction of \\{show\_info} in the code above seems
better
than the alternative of using \PASCAL's strange \\{forward} declaration for a
procedure with parameters. The \PASCAL\ convention about dropping parameters
from a post-\\{forward} procedure is, frankly, so intolerable to the author
of \TeX\ that he would rather stoop to communication via a global temporary
variable. (A similar stoopidity occurred with respect to \\{hlist\_out} and
\\{vlist\_out} above, and it will occur with respect to \\{mlist\_to\_hlist}
below.)

\Y\P\4\&{procedure}\1\  \37\\{show\_info};\C{the reader will kindly forgive
this}\2\6
\&{begin} \37$\\{show\_node\_list}(\\{info}(\\{temp\_ptr}))$;\6
\&{end};\par
\fi

\M694. \P$\X691:Declare procedures needed for displaying the elements of mlists%
\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{print\_style}(\|c:\\{integer})$;\2\6
\&{begin} \37\&{case} $\|c\mathbin{\&{div}}2$ \1\&{of}\6
\40: \37$\\{print\_esc}(\.{"displaystyle"})$;\C{$\\{display\_style}=0$}\6
\41: \37$\\{print\_esc}(\.{"textstyle"})$;\C{$\\{text\_style}=2$}\6
\42: \37$\\{print\_esc}(\.{"scriptstyle"})$;\C{$\\{script\_style}=4$}\6
\43: \37$\\{print\_esc}(\.{"scriptscriptstyle"})$;\C{$\\{script\_script%
\_style}=6$}\6
\4\&{othercases} \37$\\{print}(\.{"Unknown\ style!"})$\2\6
\&{endcases};\6
\&{end};\par
\fi

\M695. \P$\X695:Display choice node \|p\X\S$\6
\&{begin} \37$\\{print\_esc}(\.{"mathchoice"})$;\5
$\\{append\_char}(\.{"D"})$;\5
$\\{show\_node\_list}(\\{display\_mlist}(\|p))$;\5
\\{flush\_char};\5
$\\{append\_char}(\.{"T"})$;\5
$\\{show\_node\_list}(\\{text\_mlist}(\|p))$;\5
\\{flush\_char};\5
$\\{append\_char}(\.{"S"})$;\5
$\\{show\_node\_list}(\\{script\_mlist}(\|p))$;\5
\\{flush\_char};\5
$\\{append\_char}(\.{"s"})$;\5
$\\{show\_node\_list}(\\{script\_script\_mlist}(\|p))$;\5
\\{flush\_char};\6
\&{end}\par
\U section~690.\fi

\M696. \P$\X696:Display normal noad \|p\X\S$\6
\&{begin} \37\&{case} $\\{type}(\|p)$ \1\&{of}\6
\4\\{ord\_noad}: \37$\\{print\_esc}(\.{"mathord"})$;\6
\4\\{op\_noad}: \37$\\{print\_esc}(\.{"mathop"})$;\6
\4\\{bin\_noad}: \37$\\{print\_esc}(\.{"mathbin"})$;\6
\4\\{rel\_noad}: \37$\\{print\_esc}(\.{"mathrel"})$;\6
\4\\{open\_noad}: \37$\\{print\_esc}(\.{"mathopen"})$;\6
\4\\{close\_noad}: \37$\\{print\_esc}(\.{"mathclose"})$;\6
\4\\{punct\_noad}: \37$\\{print\_esc}(\.{"mathpunct"})$;\6
\4\\{inner\_noad}: \37$\\{print\_esc}(\.{"mathinner"})$;\6
\4\\{over\_noad}: \37$\\{print\_esc}(\.{"overline"})$;\6
\4\\{under\_noad}: \37$\\{print\_esc}(\.{"underline"})$;\6
\4\\{vcenter\_noad}: \37$\\{print\_esc}(\.{"vcenter"})$;\6
\4\\{radical\_noad}: \37\&{begin} \37$\\{print\_esc}(\.{"radical"})$;\5
$\\{print\_delimiter}(\\{left\_delimiter}(\|p))$;\6
\&{end};\6
\4\\{accent\_noad}: \37\&{begin} \37$\\{print\_esc}(\.{"accent"})$;\5
$\\{print\_fam\_and\_char}(\\{accent\_chr}(\|p))$;\6
\&{end};\6
\4\\{left\_noad}: \37\&{begin} \37$\\{print\_esc}(\.{"left"})$;\5
$\\{print\_delimiter}(\\{nucleus}(\|p))$;\6
\&{end};\6
\4\\{right\_noad}: \37\&{begin} \37$\\{print\_esc}(\.{"right"})$;\5
$\\{print\_delimiter}(\\{nucleus}(\|p))$;\6
\&{end};\2\6
\&{end};\6
\&{if} $\\{subtype}(\|p)\I\\{normal}$ \1\&{then}\6
\&{if} $\\{subtype}(\|p)=\\{limits}$ \1\&{then}\5
$\\{print\_esc}(\.{"limits"})$\6
\4\&{else} $\\{print\_esc}(\.{"nolimits"})$;\2\2\6
\&{if} $\\{type}(\|p)<\\{left\_noad}$ \1\&{then}\5
$\\{print\_subsidiary\_data}(\\{nucleus}(\|p),\39\.{"."})$;\2\6
$\\{print\_subsidiary\_data}(\\{supscr}(\|p),\39\.{"\↑"})$;\5
$\\{print\_subsidiary\_data}(\\{subscr}(\|p),\39\.{"\_"})$;\6
\&{end}\par
\U section~690.\fi

\M697. \P$\X697:Display fraction noad \|p\X\S$\6
\&{begin} \37$\\{print\_esc}(\.{"fraction,\ thickness\ "})$;\6
\&{if} $\\{thickness}(\|p)=\\{default\_code}$ \1\&{then}\5
$\\{print}(\.{"=\ default"})$\6
\4\&{else} $\\{print\_scaled}(\\{thickness}(\|p))$;\2\6
\&{if} $(\\{small\_fam}(\\{left\_delimiter}(\|p))\I0)\V$\ $(\\{small\_char}(%
\\{left\_delimiter}(\|p))\I\\{min\_quarterword})\V\30(\\{large\_fam}(\\{left%
\_delimiter}(\|p))\I0)\V\30(\\{large\_char}(\\{left\_delimiter}(\|p))\I\\{min%
\_quarterword})$ \&{then} \6
\&{begin} \37$\\{print}(\.{",\ left-delimiter\ "})$;\5
$\\{print\_delimiter}(\\{left\_delimiter}(\|p))$;\6
\&{end};\6
\&{if} $(\\{small\_fam}(\\{right\_delimiter}(\|p))\I0)\V\30(\\{small\_char}(%
\\{right\_delimiter}(\|p))\I\\{min\_quarterword})\V\30(\\{large\_fam}(\\{right%
\_delimiter}(\|p))\I0)\V\30(\\{large\_char}(\\{right\_delimiter}(\|p))\I\\{min%
\_quarterword})$ \1\&{then}\6
\&{begin} \37$\\{print}(\.{",\ right-delimiter\ "})$;\5
$\\{print\_delimiter}(\\{right\_delimiter}(\|p))$;\6
\&{end};\2\6
$\\{print\_subsidiary\_data}(\\{numerator}(\|p),\39\.{"\\"})$;\5
$\\{print\_subsidiary\_data}(\\{denominator}(\|p),\39\.{"/"})$; \6
\&{end} \par
\U section~690.\fi

\M698. That which can be displayed can also be destroyed.

\Y\P$\4\X698:Cases of \\{flush\_node\_list} that arise in mlists only\X\S$\6
\4\\{style\_node}: \37\&{begin} \37$\\{free\_node}(\|p,\39\\{style\_node%
\_size})$;\5
\&{goto} \37\\{done};\6
\&{end};\6
\4\\{choice\_node}: \37\&{begin} \37$\\{flush\_node\_list}(\\{display\_mlist}(%
\|p))$;\5
$\\{flush\_node\_list}(\\{text\_mlist}(\|p))$;\5
$\\{flush\_node\_list}(\\{script\_mlist}(\|p))$;\5
$\\{flush\_node\_list}(\\{script\_script\_mlist}(\|p))$;\5
$\\{free\_node}(\|p,\39\\{style\_node\_size})$;\5
\&{goto} \37\\{done};\6
\&{end};\6
\4$\\{ord\_noad},\39\\{op\_noad},\39\\{bin\_noad},\39\\{rel\_noad},\39\\{open%
\_noad},\39\\{close\_noad},\39\\{punct\_noad},\39\\{inner\_noad},\39\\{radical%
\_noad},\39\\{over\_noad},\39\\{under\_noad},\39\\{vcenter\_noad},\39\\{accent%
\_noad}$: \37\hbox{}\6
\&{begin} \37\&{if} $\\{math\_type}(\\{nucleus}(\|p))\G\\{sub\_box}$ \1\&{then}%
\5
$\\{flush\_node\_list}(\\{info}(\\{nucleus}(\|p)))$;\2\6
\&{if} $\\{math\_type}(\\{supscr}(\|p))\G\\{sub\_box}$ \1\&{then}\5
$\\{flush\_node\_list}(\\{info}(\\{supscr}(\|p)))$;\2\6
\&{if} $\\{math\_type}(\\{subscr}(\|p))\G\\{sub\_box}$ \1\&{then}\5
$\\{flush\_node\_list}(\\{info}(\\{subscr}(\|p)))$;\2\6
\&{if} $\\{type}(\|p)=\\{radical\_noad}$ \1\&{then}\5
$\\{free\_node}(\|p,\39\\{radical\_noad\_size})$\6
\4\&{else} \&{if} $\\{type}(\|p)=\\{accent\_noad}$ \1\&{then}\5
$\\{free\_node}(\|p,\39\\{accent\_noad\_size})$\6
\4\&{else} $\\{free\_node}(\|p,\39\\{noad\_size})$;\2\2\6
\&{goto} \37\\{done};\6
\&{end};\6
\4$\\{left\_noad},\39\\{right\_noad}$: \37\&{begin} \37$\\{free\_node}(\|p,\39%
\\{noad\_size})$;\5
\&{goto} \37\\{done};\6
\&{end};\6
\4\\{fraction\_noad}: \37\&{begin} \37$\\{flush\_node\_list}(\\{info}(%
\\{numerator}(\|p)))$;\5
$\\{flush\_node\_list}(\\{info}(\\{denominator}(\|p)))$;\5
$\\{free\_node}(\|p,\39\\{fraction\_noad\_size})$;\5
\&{goto} \37\\{done};\6
\&{end};\par
\U section~202.\fi

\N699.  \[35] Subroutines for math mode.
In order to convert mlists to hlists, i.e., noads to nodes, we need several
subroutines that are conveniently dealt with now.

Let us first introduce the macros that make it easy to get at the parameters
and
other font information. A size code, which is a multiple of 16, is added to a
family number to get an index into the table of internal font numbers
for each combination of family and size.  (Be alert: Size codes get
larger as the type gets smaller.)

\Y\P\D \37$\\{text\_size}=0$\C{size code for the largest size in a family}\par
\P\D \37$\\{script\_size}=16$\C{size code for the medium size in a family}\par
\P\D \37$\\{script\_script\_size}=32$\C{size code for the smallest size in a
family}\par
\Y\P$\4\X57:Basic printing procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{print\_size}(\|s:\\{integer})$;\2\6
\&{begin} \37\&{if} $\|s=0$ \1\&{then}\5
$\\{print\_esc}(\.{"textfont"})$\6
\4\&{else} \&{if} $\|s=\\{script\_size}$ \1\&{then}\5
$\\{print\_esc}(\.{"scriptfont"})$\6
\4\&{else} $\\{print\_esc}(\.{"scriptscriptfont"})$;\2\2\6
\&{end};\par
\fi

\M700. Before an mlist is converted to an hlist, \TeX\ makes sure that
the fonts in family~2 have enough parameters to be math-symbol
fonts, and that the fonts in family~3 have enough parameters to be
math-extension fonts. The math-symbol parameters are referred to by using the
following macros, which take a size code as their parameter; for example,
$\\{num1}(\\{cur\_size})$ gives the value of the \\{num1} parameter for the
current size.

\Y\P\D \37$\\{mathsy\_end}(\#)\S\\{fam\_fnt}(2+\#)$ ] ] .\\{sc}\par
\P\D $\\{mathsy}(\#)\S\\{font\_info}$ [ $\#+\\{param\_base}$ [ $\\{mathsy%
\_end}$\par
\P\D \37$\\{math\_x\_height}\S\\{mathsy}(5)$\C{height of `\.x'}\par
\P\D \37$\\{math\_quad}\S\\{mathsy}(6)$\C{\.{18mu}}\par
\P\D \37$\\{num1}\S\\{mathsy}(8)$\C{numerator shift-up in display styles}\par
\P\D \37$\\{num2}\S\\{mathsy}(9)$\C{numerator shift-up in non-display, non-\.{%
\\atop}}\par
\P\D \37$\\{num3}\S\\{mathsy}(10)$\C{numerator shift-up in non-display \.{%
\\atop}}\par
\P\D \37$\\{denom1}\S\\{mathsy}(11)$\C{denominator shift-down in display
styles}\par
\P\D \37$\\{denom2}\S\\{mathsy}(12)$\C{denominator shift-down in non-display
styles}\par
\P\D \37$\\{sup1}\S\\{mathsy}(13)$\C{superscript shift-up in uncramped display
style}\par
\P\D \37$\\{sup2}\S\\{mathsy}(14)$\C{superscript shift-up in uncramped
non-display}\par
\P\D \37$\\{sup3}\S\\{mathsy}(15)$\C{superscript shift-up in cramped styles}\par
\P\D \37$\\{sub1}\S\\{mathsy}(16)$\C{subscript shift-down if superscript is
absent}\par
\P\D \37$\\{sub2}\S\\{mathsy}(17)$\C{subscript shift-down if superscript is
present}\par
\P\D \37$\\{sup\_drop}\S\\{mathsy}(18)$\C{superscript baseline below top of
large box}\par
\P\D \37$\\{sub\_drop}\S\\{mathsy}(19)$\C{subscript baseline below bottom of
large box}\par
\P\D \37$\\{delim1}\S\\{mathsy}(20)$\C{size of \.{\\atopwithdelims} delimiters
	in display styles}\par
\P\D \37$\\{delim2}\S\\{mathsy}(21)$\C{size of \.{\\atopwithdelims} delimiters
in non-displays}\par
\P\D \37$\\{axis\_height}\S\\{mathsy}(22)$\C{height of fraction lines above the
baseline}\par
\P\D \37$\\{total\_mathsy\_params}=22$\par
\fi

\M701. The math-extension parameters have similar macros, but the size code is
omitted (since it is always \\{cur\_size} when we refer to such parameters).

\Y\P\D \37$\\{mathex}(\#)\S\\{font\_info}[\#+\\{param\_base}[\\{fam\_fnt}(3+%
\\{cur\_size})]].\\{sc}$\par
\P\D \37$\\{default\_rule\_thickness}\S\\{mathex}(8)$\C{thickness of \.{\\over}
bars}\par
\P\D \37$\\{big\_op\_spacing1}\S\\{mathex}(9)$\C{minimum clearance above a
displayed op}\par
\P\D \37$\\{big\_op\_spacing2}\S\\{mathex}(10)$\C{minimum clearance below a
displayed op}\par
\P\D \37$\\{big\_op\_spacing3}\S\\{mathex}(11)$\C{minimum baselineskip above
displayed op}\par
\P\D \37$\\{big\_op\_spacing4}\S\\{mathex}(12)$\C{minimum baselineskip below
displayed op}\par
\P\D \37$\\{big\_op\_spacing5}\S\\{mathex}(13)$\C{padding above and below
displayed limits}\par
\P\D \37$\\{total\_mathex\_params}=13$\par
\fi

\M702. We also need to compute the change in style between mlists and their
subsidiaries. The following macros define the subsidiary style for
an overlined nucleus (\\{cramped\_style}), for a subscript or a superscript
(\\{sub\_style} or \\{sup\_style}), or for a numerator or denominator (\\{num%
\_style}
or \\{denom\_style}).

\Y\P\D \37$\\{cramped\_style}(\#)\S2\ast(\#\mathbin{\&{div}}2)+\\{cramped}$%
\C{cramp the style}\par
\P\D \37$\\{sub\_style}(\#)\S2\ast(\#\mathbin{\&{div}}4)+\\{script\_style}+%
\\{cramped}$\C{smaller and cramped}\par
\P\D \37$\\{sup\_style}(\#)\S2\ast(\#\mathbin{\&{div}}4)+\\{script\_style}+(\#%
\mathbin{\&{mod}}2)$\C{smaller}\par
\P\D \37$\\{num\_style}(\#)\S\#+2-2\ast(\#\mathbin{\&{div}}6)$\C{smaller unless
already script-script}\par
\P\D \37$\\{denom\_style}(\#)\S2\ast(\#\mathbin{\&{div}}2)+\\{cramped}+2-2\ast(%
\#\mathbin{\&{div}}6)$\C{smaller, cramped}\par
\fi

\M703. When the style changes, the following piece of program computes
associated
information:

\Y\P$\4\X703:Set up the values of \\{cur\_size} and \\{cur\_mu}, based on %
\\{cur\_style}\X\S$\6
\&{begin} \37\&{if} $\\{cur\_style}<\\{script\_style}$ \1\&{then}\5
$\\{cur\_size}\K\\{text\_size}$\6
\4\&{else} $\\{cur\_size}\K16\ast((\\{cur\_style}-\\{text\_style})\mathbin{%
\&{div}}2)$;\2\6
$\\{cur\_mu}\K\\{x\_over\_n}(\\{math\_quad}(\\{cur\_size}),\3918)$;\6
\&{end}\par
\U sections~720, 726, 730, 754, 760, and~763.\fi

\M704. Here is a function that returns a pointer to a rule node having a given
thickness \|t. The rule will extend horizontally to the boundary of the vlist
that eventually contains it.

\Y\P\4\&{function}\1\  \37$\\{fraction\_rule}(\|t:\\{scaled})$: \37\\{pointer};%
\C{construct the bar for a fraction}\6
\4\&{var} \37\|p: \37\\{pointer};\C{the new node}\2\6
\&{begin} \37$\|p\K\\{new\_rule}$;\5
$\\{height}(\|p)\K\|t$;\5
$\\{depth}(\|p)\K0$;\5
$\\{fraction\_rule}\K\|p$;\6
\&{end};\par
\fi

\M705. The \\{overbar} function returns a pointer to a vlist box that consists
of
a given box \|b, above which has been placed a kern of height \|k under a
fraction rule of thickness \|t under additional space of height \|t.

\Y\P\4\&{function}\1\  \37$\\{overbar}(\|b:\\{pointer};\,\35\|k,\39\|t:%
\\{scaled})$: \37\\{pointer};\6
\4\&{var} \37$\|p,\39\|q$: \37\\{pointer};\C{nodes being constructed}\2\6
\&{begin} \37$\|p\K\\{new\_kern}(\|k)$;\5
$\\{link}(\|p)\K\|b$;\5
$\|q\K\\{fraction\_rule}(\|t)$;\5
$\\{link}(\|q)\K\|p$;\5
$\|p\K\\{new\_kern}(\|t)$;\5
$\\{link}(\|p)\K\|q$;\5
$\\{overbar}\K\\{vpack}(\|p,\39\\{natural})$;\6
\&{end};\par
\fi

\M706. The \\{var\_delimiter} function, which finds or constructs a
sufficiently
large delimiter, is the most interesting of the auxiliary functions that
currently concern us. Given a pointer \|d to a delimiter field in some noad,
together with a size code \|s and a vertical distance \|v, this function
returns a pointer to a box that contains the smallest variant of \|d whose
height plus depth is \|v or more. (And if no variant is large enough, it
returns the largest available variant.) In particular, this routine will
construct arbitrarily large delimiters from extensible components, if
\|d leads to such characters.

The value returned is a box whose \\{shift\_amount} has been set so that
the box is vertically centered with respect to the axis in the given size.
If a built-up symbol is returned, the height of the box before shifting
will be the height of its topmost component.

\Y\P\hbox{\4}\X709:Declare subprocedures for \\{var\_delimiter}\X \6
\4\&{function}\1\  \37$\\{var\_delimiter}(\|d:\\{pointer};\,\35\|s:\\{small%
\_number};\,\35\|v:\\{scaled})$: \37\\{pointer};\6
\4\&{label} \37$\\{found},\39\\{continue}$;\6
\4\&{var} \37\|b: \37\\{pointer};\C{the box that will be constructed}\6
$\|f,\39\|g$: \37\\{internal\_font\_number};\C{best-so-far and tentative font
codes}\6
$\|c,\39\|x,\39\|y$: \37\\{quarterword};\C{best-so-far and tentative character
codes}\6
$\|m,\39\|n$: \37\\{integer};\C{the number of extensible pieces}\6
\|u: \37\\{scaled};\C{height-plus-depth of a tentative character}\6
\|w: \37\\{scaled};\C{largest height-plus-depth so far}\6
\|q: \37\\{four\_quarters};\C{character info}\6
\\{hd}: \37\\{eight\_bits};\C{height-depth byte}\6
\|r: \37\\{four\_quarters};\C{extensible pieces}\6
\|z: \37\\{small\_number};\C{runs through font family members}\6
\\{large\_attempt}: \37\\{boolean};\C{are we trying the ``large'' variant?}\2\6
\&{begin} \37$\|f\K\\{null\_font}$;\5
$\|w\K0$;\5
$\\{large\_attempt}\K\\{false}$;\5
$\|z\K\\{small\_fam}(\|d)$;\5
$\|x\K\\{small\_char}(\|d)$;\6
\~ \1\&{loop}\ \&{begin} \37\X707:Look at the variants of $(\|z,\|x)$; set \|f
and \|c whenever a better character is found; \&{goto} \\{found} as soon as a
large enough variant is encountered\X;\6
\&{if} $\\{large\_attempt}$ \1\&{then}\5
\&{goto} \37\\{found};\C{there were none large enough}\2\6
$\\{large\_attempt}\K\\{true}$;\5
$\|z\K\\{large\_fam}(\|d)$;\5
$\|x\K\\{large\_char}(\|d)$;\6
\&{end};\2\6
\4\\{found}: \37\&{if} $\|f\I\\{null\_font}$ \1\&{then}\5
\X710:Make variable \|b point to a box for $(\|f,\|c)$\X\6
\4\&{else} \&{begin} \37$\|b\K\\{new\_null\_box}$;\5
$\\{width}(\|b)\K\\{null\_delimiter\_space}$;\C{use this width if no delimiter
was found}\6
\&{end};\2\6
$\\{shift\_amount}(\|b)\K\\{half}(\\{height}(\|b)-\\{depth}(\|b))-\\{axis%
\_height}(\|s)$;\5
$\\{var\_delimiter}\K\|b$;\6
\&{end};\par
\fi

\M707. The search process is complicated slightly by the facts that some of the
characters might not be present in some of the fonts, and they might not
be probed in increasing order of height.

\Y\P$\4\X707:Look at the variants of $(\|z,\|x)$; set \|f and \|c whenever a
better character is found; \&{goto} \\{found} as soon as a large enough variant
is encountered\X\S$\6
\&{if} $(\|z\I0)\V(\|x\I\\{min\_quarterword})$ \1\&{then}\6
\&{begin} \37$\|z\K\|z+\|s+16$;\6
\1\&{repeat} \37$\|z\K\|z-16$;\5
$\|g\K\\{fam\_fnt}(\|z)$;\6
\&{if} $\|g\I\\{null\_font}$ \1\&{then}\5
\X708:Look at the list of characters starting with \|x in font \|g; set \|f and
\|c whenever a better character is found; \&{goto} \\{found} as soon as a large
enough variant is encountered\X;\2\6
\4\&{until}\5
$\|z<16$;\2\6
\&{end}\2\par
\U section~706.\fi

\M708. \P$\X708:Look at the list of characters starting with \|x in font \|g;
set \|f and \|c whenever a better character is found; \&{goto} \\{found} as
soon as a large enough variant is encountered\X\S$\6
\&{begin} \37$\|y\K\|x$;\6
\4\\{continue}: \37\&{if} $(\\{qo}(\|y)\G\\{font\_bc}[\|g])\W(\\{qo}(\|y)\L%
\\{font\_ec}[\|g])$ \1\&{then}\6
\&{begin} \37$\|q\K\\{char\_info}(\|g)(\|y)$;\6
\&{if} $\\{char\_exists}(\|q)$ \1\&{then}\6
\&{begin} \37\&{if} $\\{char\_tag}(\|q)=\\{ext\_tag}$ \1\&{then}\6
\&{begin} \37$\|f\K\|g$;\5
$\|c\K\|y$;\5
\&{goto} \37\\{found};\6
\&{end};\2\6
$\\{hd}\K\\{height\_depth}(\|q)$;\5
$\|u\K\\{char\_height}(\|g)(\\{hd})+\\{char\_depth}(\|g)(\\{hd})$;\6
\&{if} $\|u>\|w$ \1\&{then}\6
\&{begin} \37$\|f\K\|g$;\5
$\|c\K\|y$;\5
$\|w\K\|u$;\6
\&{if} $\|u\G\|v$ \1\&{then}\5
\&{goto} \37\\{found};\2\6
\&{end};\2\6
\&{if} $\\{char\_tag}(\|q)=\\{list\_tag}$ \1\&{then}\6
\&{begin} \37$\|y\K\\{rem\_byte}(\|q)$;\5
\&{goto} \37\\{continue};\6
\&{end};\2\6
\&{end};\2\6
\&{end};\2\6
\&{end}\par
\U section~707.\fi

\M709. Here is a subroutine that creates a new box, whose contents is a
single character, and whose width includes the italic correction for
that character. The height or depth of the box will be negative, if
the height or depth of the character is negative; thus, this routine
may deliver a slightly different result than \\{hpack} would produce.

\Y\P$\4\X709:Declare subprocedures for \\{var\_delimiter}\X\S$\6
\4\&{function}\1\  \37$\\{char\_box}(\|f:\\{internal\_font\_number};\,\35\|c:%
\\{quarterword})$: \37\\{pointer};\6
\4\&{var} \37\|q: \37\\{four\_quarters};\5
\\{hd}: \37\\{eight\_bits};\C{\\{height\_depth} byte}\6
$\|b,\39\|p$: \37\\{pointer};\C{the new box and its character node}\2\6
\&{begin} \37$\|q\K\\{char\_info}(\|f)(\|c)$;\5
$\\{hd}\K\\{height\_depth}(\|q)$;\5
$\|b\K\\{new\_null\_box}$;\5
$\\{width}(\|b)\K\\{char\_width}(\|f)(\|q)+\\{char\_italic}(\|f)(\|q)$;\5
$\\{height}(\|b)\K\\{char\_height}(\|f)(\\{hd})$;\5
$\\{depth}(\|b)\K\\{char\_depth}(\|f)(\\{hd})$;\5
$\|p\K\\{get\_avail}$;\5
$\\{character}(\|p)\K\|c$;\5
$\\{font}(\|p)\K\|f$;\5
$\\{list\_ptr}(\|b)\K\|p$;\5
$\\{char\_box}\K\|b$;\6
\&{end};\par
\A sections~711 and~712.
\U section~706.\fi

\M710. When the following code is executed, $\\{char\_tag}(\|q)$ will be equal
to
\\{ext\_tag} if and only if a built-up symbol is supposed to be returned.

\Y\P$\4\X710:Make variable \|b point to a box for $(\|f,\|c)$\X\S$\6
\&{if} $\\{char\_tag}(\|q)=\\{ext\_tag}$ \1\&{then}\5
\X713:Construct an extensible character in a new box \|b, using recipe $\\{rem%
\_byte}(\|q)$ and font \|f\X\6
\4\&{else} $\|b\K\\{char\_box}(\|f,\39\|c)$\2\par
\U section~706.\fi

\M711. When we build an extensible character, it's handy to have the
following subroutine, which puts a given character on top
of the characters already in box \|b:

\Y\P$\4\X709:Declare subprocedures for \\{var\_delimiter}\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{stack\_into\_box}(\|b:\\{pointer};\,\35\|f:%
\\{internal\_font\_number};\,\35\|c:\\{quarterword})$;\6
\4\&{var} \37\|p: \37\\{pointer};\C{new node placed into \|b}\2\6
\&{begin} \37$\|p\K\\{char\_box}(\|f,\39\|c)$;\5
$\\{link}(\|p)\K\\{list\_ptr}(\|b)$;\5
$\\{list\_ptr}(\|b)\K\|p$;\5
$\\{height}(\|b)\K\\{height}(\|p)$;\6
\&{end};\par
\fi

\M712. Another handy subroutine computes the height plus depth of
a given character:

\Y\P$\4\X709:Declare subprocedures for \\{var\_delimiter}\X\mathrel{+}\S$\6
\4\&{function}\1\  \37$\\{height\_plus\_depth}(\|f:\\{internal\_font\_number};%
\,\35\|c:\\{quarterword})$: \37\\{scaled};\6
\4\&{var} \37\|q: \37\\{four\_quarters};\5
\\{hd}: \37\\{eight\_bits};\C{\\{height\_depth} byte}\2\6
\&{begin} \37$\|q\K\\{char\_info}(\|f)(\|c)$;\5
$\\{hd}\K\\{height\_depth}(\|q)$;\5
$\\{height\_plus\_depth}\K\\{char\_height}(\|f)(\\{hd})+\\{char\_depth}(\|f)(%
\\{hd})$;\6
\&{end};\par
\fi

\M713. \P$\X713:Construct an extensible character in a new box \|b, using
recipe $\\{rem\_byte}(\|q)$ and font \|f\X\S$\6
\&{begin} \37$\|b\K\\{new\_null\_box}$;\5
$\\{type}(\|b)\K\\{vlist\_node}$;\5
$\|r\K\\{font\_info}[\\{exten\_base}[\|f]+\\{rem\_byte}(\|q)].\\{qqqq}$;\6
\X714:Compute the minimum suitable height, \|w, and the corresponding number of
extension steps, \|n; also set $\\{width}(\|b)$\X;\6
$\|c\K\\{ext\_bot}(\|r)$;\6
\&{if} $\|c\I\\{min\_quarterword}$ \1\&{then}\5
$\\{stack\_into\_box}(\|b,\39\|f,\39\|c)$;\2\6
$\|c\K\\{ext\_rep}(\|r)$;\6
\&{for} $\|m\K1\mathrel{\&{to}}\|n$ \1\&{do}\5
$\\{stack\_into\_box}(\|b,\39\|f,\39\|c)$;\2\6
$\|c\K\\{ext\_mid}(\|r)$;\6
\&{if} $\|c\I\\{min\_quarterword}$ \1\&{then}\6
\&{begin} \37$\\{stack\_into\_box}(\|b,\39\|f,\39\|c)$;\5
$\|c\K\\{ext\_rep}(\|r)$;\6
\&{for} $\|m\K1\mathrel{\&{to}}\|n$ \1\&{do}\5
$\\{stack\_into\_box}(\|b,\39\|f,\39\|c)$;\2\6
\&{end};\2\6
$\|c\K\\{ext\_top}(\|r)$;\6
\&{if} $\|c\I\\{min\_quarterword}$ \1\&{then}\5
$\\{stack\_into\_box}(\|b,\39\|f,\39\|c)$;\2\6
$\\{depth}(\|b)\K\|w-\\{height}(\|b)$;\6
\&{end}\par
\U section~710.\fi

\M714. The width of an extensible character is the width of the repeatable
module. If this module does not have positive height plus depth,
we don't use any copies of it, otherwise we use as few as possible
(in groups of two if there is a middle part).

\Y\P$\4\X714:Compute the minimum suitable height, \|w, and the corresponding
number of extension steps, \|n; also set $\\{width}(\|b)$\X\S$\6
$\|c\K\\{ext\_rep}(\|r)$;\5
$\|u\K\\{height\_plus\_depth}(\|f,\39\|c)$;\5
$\|w\K0$;\5
$\|q\K\\{char\_info}(\|f)(\|c)$;\5
$\\{width}(\|b)\K\\{char\_width}(\|f)(\|q)+\\{char\_italic}(\|f)(\|q)$;\6
$\|c\K\\{ext\_bot}(\|r)$;\ \&{if} $\|c\I\\{min\_quarterword}$ \1\&{then}\5
$\|w\K\|w+\\{height\_plus\_depth}(\|f,\39\|c)$;\2\6
$\|c\K\\{ext\_mid}(\|r)$;\ \&{if} $\|c\I\\{min\_quarterword}$ \1\&{then}\5
$\|w\K\|w+\\{height\_plus\_depth}(\|f,\39\|c)$;\2\6
$\|c\K\\{ext\_top}(\|r)$;\ \&{if} $\|c\I\\{min\_quarterword}$ \1\&{then}\5
$\|w\K\|w+\\{height\_plus\_depth}(\|f,\39\|c)$;\2\6
$\|n\K0$;\6
\&{if} $\|u>0$ \1\&{then}\6
\&{while} $\|w<\|v$ \1\&{do}\6
\&{begin} \37$\|w\K\|w+\|u$;\5
$\\{incr}(\|n)$;\6
\&{if} $\\{ext\_mid}(\|r)\I\\{min\_quarterword}$ \1\&{then}\5
$\|w\K\|w+\|u$;\2\6
\&{end}\2\2\par
\U section~713.\fi

\M715. The next subroutine is much simpler; it is used for numerators and
denominators of fractions as well as for displayed operators and
their limits above and below. It takes a given box~\|b and
changes it so that the new box is centered in a box of width~\|w.
The centering is done by putting \.{\\hss} glue at the left and right
of the list inside \|b, then packaging the new box; thus, the
actual box might not really be centered, if it already contains
infinite glue.

The given box might contain a single character whose italic correction
has been added to the width of the box; in this case a compensating
kern is inserted.

\Y\P\4\&{function}\1\  \37$\\{rebox}(\|b:\\{pointer};\,\35\|w:\\{scaled})$: \37%
\\{pointer};\6
\4\&{var} \37\|p: \37\\{pointer};\C{temporary register for list manipulation}\6
\|f: \37\\{internal\_font\_number};\C{font in a one-character box}\6
\|v: \37\\{scaled};\C{width of a character without italic correction}\2\6
\&{begin} \37\&{if} $(\\{width}(\|b)\I\|w)\W(\\{list\_ptr}(\|b)\I\\{null})$ \1%
\&{then}\6
\&{begin} \37\&{if} $\\{type}(\|b)=\\{vlist\_node}$ \1\&{then}\5
$\|b\K\\{hpack}(\|b,\39\\{natural})$;\2\6
$\|p\K\\{list\_ptr}(\|b)$;\6
\&{if} $(\\{is\_char\_node}(\|p))\W(\\{link}(\|p)=\\{null})$ \1\&{then}\6
\&{begin} \37$\|f\K\\{font}(\|p)$;\5
$\|v\K\\{char\_width}(\|f)(\\{char\_info}(\|f)(\\{character}(\|p)))$;\6
\&{if} $\|v\I\\{width}(\|b)$ \1\&{then}\5
$\\{link}(\|p)\K\\{new\_kern}(\\{width}(\|b)-\|v)$;\2\6
\&{end};\2\6
$\\{free\_node}(\|b,\39\\{box\_node\_size})$;\5
$\|b\K\\{new\_glue}(\\{ss\_glue})$;\5
$\\{link}(\|b)\K\|p$;\6
\&{while} $\\{link}(\|p)\I\\{null}$ \1\&{do}\5
$\|p\K\\{link}(\|p)$;\2\6
$\\{link}(\|p)\K\\{new\_glue}(\\{ss\_glue})$;\5
$\\{rebox}\K\\{hpack}(\|b,\39\|w,\39\\{exactly})$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{width}(\|b)\K\|w$;\5
$\\{rebox}\K\|b$;\6
\&{end};\2\6
\&{end};\par
\fi

\M716. Here is a subroutine that creates a new glue specification from another
one that is expressed in `\.{mu}', given the value of the math unit.

\Y\P\D \37$\\{mu\_mult}(\#)\S\\{nx\_plus\_y}(\|n,\39\#,\39\\{xn\_over\_d}(\#,%
\39\|f,\39\O{200000}))$\par
\Y\P\4\&{function}\1\  \37$\\{math\_glue}(\|g:\\{pointer};\,\35\|m:%
\\{scaled})$: \37\\{pointer};\6
\4\&{var} \37\|p: \37\\{pointer};\C{the new glue specification}\6
\|n: \37\\{integer};\C{integer part of \|m}\6
\|f: \37\\{scaled};\C{fraction part of \|m}\2\6
\&{begin} \37$\|n\K\\{x\_over\_n}(\|m,\39\O{200000})$;\5
$\|f\K\\{remainder}$;\6
$\|p\K\\{get\_node}(\\{glue\_spec\_size})$;\5
$\\{width}(\|p)\K\\{mu\_mult}(\\{width}(\|g))$;\C{convert \.{mu} to \.{pt}}\6
$\\{stretch\_order}(\|p)\K\\{stretch\_order}(\|g)$;\6
\&{if} $\\{stretch\_order}(\|p)=\\{normal}$ \1\&{then}\5
$\\{stretch}(\|p)\K\\{mu\_mult}(\\{stretch}(\|g))$\6
\4\&{else} $\\{stretch}(\|p)\K\\{stretch}(\|g)$;\2\6
$\\{shrink\_order}(\|p)\K\\{shrink\_order}(\|g)$;\6
\&{if} $\\{shrink\_order}(\|p)=\\{normal}$ \1\&{then}\5
$\\{shrink}(\|p)\K\\{mu\_mult}(\\{shrink}(\|g))$\6
\4\&{else} $\\{shrink}(\|p)\K\\{shrink}(\|g)$;\2\6
$\\{math\_glue}\K\|p$;\6
\&{end};\par
\fi

\M717. The \\{math\_kern} subroutine removes \\{mu\_glue} from a kern node,
given
the value of the math unit.

\Y\P\4\&{procedure}\1\  \37$\\{math\_kern}(\|p:\\{pointer};\,\35\|m:%
\\{scaled})$;\6
\4\&{var} \37\|n: \37\\{integer};\C{integer part of \|m}\6
\|f: \37\\{scaled};\C{fraction part of \|m}\2\6
\&{begin} \37\&{if} $\\{subtype}(\|p)=\\{mu\_glue}$ \1\&{then}\6
\&{begin} \37$\|n\K\\{x\_over\_n}(\|m,\39\O{200000})$;\5
$\|f\K\\{remainder}$;\6
$\\{width}(\|p)\K\\{mu\_mult}(\\{width}(\|p))$;\5
$\\{subtype}(\|p)\K\\{normal}$;\6
\&{end};\2\6
\&{end};\par
\fi

\M718. Sometimes it is necessary to destroy an mlist. The following
subroutine empties the current list, assuming that $\\{abs}(\\{mode})=%
\\{mmode}$.

\Y\P\4\&{procedure}\1\  \37\\{flush\_math};\2\6
\&{begin} \37$\\{flush\_node\_list}(\\{link}(\\{head}))$;\5
$\\{flush\_node\_list}(\\{incompleat\_noad})$;\5
$\\{link}(\\{head})\K\\{null}$;\5
$\\{tail}\K\\{head}$;\5
$\\{incompleat\_noad}\K\\{null}$;\6
\&{end};\par
\fi

\N719.  \[36] Typesetting math formulas.
\TeX's most important routine for dealing with formulas is called
\\{mlist\_to\_hlist}.  After a formula has been scanned and represented as an
mlist, this routine converts it to an hlist that can be placed into a box
or incorporated into the text of a paragraph. There are three implicit
parameters, passed in global variables: \\{cur\_mlist} points to the first
node or noad in the given mlist (and it might be \\{null}); \\{cur\_style} is a
style code; and \\{mlist\_penalties} is \\{true} if penalty nodes for potential
line breaks are to be inserted into the resulting hlist. After
\\{mlist\_to\_hlist} has acted, $\\{link}(\\{temp\_head})$ points to the
translated hlist.

Since mlists can be inside mlists, the procedure is recursive. And since this
is not part of \TeX's inner loop, the program has been written in a manner
that stresses compactness over efficiency.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{cur\_mlist}: \37\\{pointer};\C{beginning of mlist to be translated}\6
\4\\{cur\_style}: \37\\{small\_number};\C{style code at current place in the
list}\6
\4\\{cur\_size}: \37\\{small\_number};\C{size code corresponding to \\{cur%
\_style}}\6
\4\\{cur\_mu}: \37\\{scaled};\C{the math unit width corresponding to \\{cur%
\_size}}\6
\4\\{mlist\_penalties}: \37\\{boolean};\C{should \\{mlist\_to\_hlist} insert
penalties?}\par
\fi

\M720. The recursion in \\{mlist\_to\_hlist} is due primarily to a subroutine
called \\{clean\_box} that puts a given noad field into a box using a given
math style; \\{mlist\_to\_hlist} can call \\{clean\_box}, which can call
\\{mlist\_to\_hlist}. The box returned by \\{clean\_box} is ``clean'' in the
sense that its \\{shift\_amount} is zero.

\Y\P\4\&{procedure}\1\  \37\\{mlist\_to\_hlist};\5
\\{forward};\5
\hbox{\2}\6
\4\&{function}\1\  \37$\\{clean\_box}(\|p:\\{pointer};\,\35\|s:\\{small%
\_number})$: \37\\{pointer};\6
\4\&{label} \37\\{found};\6
\4\&{var} \37\|q: \37\\{pointer};\C{beginning of a list to be boxed}\6
\\{save\_style}: \37\\{small\_number};\C{\\{cur\_style} to be restored}\6
\|x: \37\\{pointer};\C{box to be returned}\6
\|r: \37\\{pointer};\C{temporary pointer}\2\6
\&{begin} \37\&{case} $\\{math\_type}(\|p)$ \1\&{of}\6
\4\\{math\_char}: \37\&{begin} \37$\\{cur\_mlist}\K\\{new\_noad}$;\5
$\\{mem}[\\{nucleus}(\\{cur\_mlist})]\K\\{mem}[\|p]$;\6
\&{end};\6
\4\\{sub\_box}: \37\&{begin} \37$\|q\K\\{info}(\|p)$;\5
\&{goto} \37\\{found};\6
\&{end};\6
\4\\{sub\_mlist}: \37$\\{cur\_mlist}\K\\{info}(\|p)$;\6
\4\&{othercases} \37\&{begin} \37$\|q\K\\{new\_null\_box}$;\5
\&{goto} \37\\{found};\6
\&{end}\2\6
\&{endcases};\6
$\\{save\_style}\K\\{cur\_style}$;\5
$\\{cur\_style}\K\|s$;\5
$\\{mlist\_penalties}\K\\{false}$;\6
\\{mlist\_to\_hlist};\5
$\|q\K\\{link}(\\{temp\_head})$;\C{recursive call}\6
$\\{cur\_style}\K\\{save\_style}$;\C{restore the style}\6
\X703:Set up the values of \\{cur\_size} and \\{cur\_mu}, based on \\{cur%
\_style}\X;\6
\4\\{found}: \37\&{if} $\\{is\_char\_node}(\|q)\V(\|q=\\{null})$ \1\&{then}\5
$\|x\K\\{hpack}(\|q,\39\\{natural})$\6
\4\&{else} \&{if} $(\\{link}(\|q)=\\{null})\W(\\{type}(\|q)\L\\{vlist\_node})%
\W(\\{shift\_amount}(\|q)=0)$ \1\&{then}\5
$\|x\K\|q$\C{it's already clean}\6
\4\&{else} $\|x\K\\{hpack}(\|q,\39\\{natural})$;\2\2\6
\X721:Simplify a trivial box\X;\6
$\\{clean\_box}\K\|x$;\6
\&{end};\par
\fi

\M721. Here we save memory space in a common case.

\Y\P$\4\X721:Simplify a trivial box\X\S$\6
$\|q\K\\{list\_ptr}(\|x)$;\6
\&{if} $\\{is\_char\_node}(\|q)$ \1\&{then}\6
\&{begin} \37$\|r\K\\{link}(\|q)$;\6
\&{if} $\|r\I\\{null}$ \1\&{then}\6
\&{if} $\\{link}(\|r)=\\{null}$ \1\&{then}\6
\&{if} $\R\\{is\_char\_node}(\|r)$ \1\&{then}\6
\&{if} $\\{type}(\|r)=\\{kern\_node}$ \1\&{then}\6
\&{begin} \37$\\{free\_node}(\|r,\39\\{small\_node\_size})$;\5
$\\{link}(\|q)\K\\{null}$;\6
\&{end};\2\2\2\2\6
\&{end}\2\par
\U section~720.\fi

\M722. It is convenient to have a procedure that converts a \\{math\_char}
field to an ``unpacked'' form. The \\{fetch} routine sets \\{cur\_f}, \\{cur%
\_c},
and \\{cur\_i} to the font code, character code, and character information
bytes of
a given noad field. It also takes care of issuing error messages for
nonexistent characters; in such cases, $\\{char\_exists}(\\{cur\_i})$ will be %
\\{false}
after \\{fetch} has acted, and the field will also have been reset to %
\\{empty}.

\Y\P\4\&{procedure}\1\  \37$\\{fetch}(\|a:\\{pointer})$;\C{unpack the \\{math%
\_char} field \|a}\2\6
\&{begin} \37$\\{cur\_c}\K\\{character}(\|a)$;\5
$\\{cur\_f}\K\\{fam\_fnt}(\\{fam}(\|a)+\\{cur\_size})$;\6
\&{if} $\\{cur\_f}=\\{null\_font}$ \1\&{then}\5
\X723:Complain about an undefined family and set \\{cur\_i} null\X\6
\4\&{else} \&{begin} \37\&{if} $(\\{qo}(\\{cur\_c})\G\\{font\_bc}[\\{cur\_f}])%
\W(\\{qo}(\\{cur\_c})\L\\{font\_ec}[\\{cur\_f}])$ \1\&{then}\5
$\\{cur\_i}\K\\{char\_info}(\\{cur\_f})(\\{cur\_c})$\6
\4\&{else} $\\{cur\_i}\K\\{null\_character}$;\2\6
\&{if} $\R(\\{char\_exists}(\\{cur\_i}))$ \1\&{then}\6
\&{begin} \37$\\{char\_warning}(\\{cur\_f},\39\\{qo}(\\{cur\_c}))$;\5
$\\{math\_type}(\|a)\K\\{empty}$;\6
\&{end};\2\6
\&{end};\2\6
\&{end};\par
\fi

\M723. \P$\X723:Complain about an undefined family and set \\{cur\_i} null\X\S$%
\6
\&{begin} \37$\\{print\_err}(\.{""})$;\5
$\\{print\_size}(\\{cur\_size})$;\5
$\\{print\_char}(\.{"\ "})$;\5
$\\{print\_int}(\\{fam}(\|a))$;\5
$\\{print}(\.{"\ is\ undefined\ (character\ "})$;\5
$\\{print\_ASCII}(\\{qo}(\\{cur\_c}))$;\5
$\\{print\_char}(\.{")"})$;\5
$\\{help4}(\.{"Somewhere\ in\ the\ math\ formula\ just\ ended,\ you\ used\
the"})$\6
$(\.{"stated\ character\ from\ an\ undefined\ font\ family.\ For\ example,"})$\6
$(\.{"plain\ TeX\ doesn\'t\ allow\ \\it\ or\ \\sl\ in\ subscripts.\
Proceed,"})$\6
$(\.{"and\ I\'ll\ try\ to\ forget\ that\ I\ needed\ that\ character."})$;\5
\\{error};\5
$\\{cur\_i}\K\\{null\_character}$;\5
$\\{math\_type}(\|a)\K\\{empty}$;\6
\&{end}\par
\U section~722.\fi

\M724. The outputs of \\{fetch} are placed in global variables.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{cur\_f}: \37\\{internal\_font\_number};\C{the \\{font} field of a \\{math%
\_char}}\6
\4\\{cur\_c}: \37\\{quarterword};\C{the \\{character} field of a \\{math%
\_char}}\6
\4\\{cur\_i}: \37\\{four\_quarters};\C{the \\{char\_info} of a \\{math\_char},
	or a lig/kern instruction}\par
\fi

\M725. We need to do a lot of different things, so \\{mlist\_to\_hlist} makes
two
passes over the given mlist.

The first pass does most of the processing: It removes ``mu'' spacing from
glue, it recursively evaluates all subsidiary mlists so that only the
top-level mlist remains to be handled, it puts fractions and square roots
and such things into boxes, it attaches subscripts and superscripts, and
it computes the overall height and depth of the top-level mlist so that
the size of delimiters for a \\{left\_noad} and a \\{right\_noad} will be
known.
The hlist resulting from each noad is recorded in that noad's \\{new\_hlist}
field, an integer field that replaces the \\{nucleus} or \\{thickness}.

The second pass eliminates all noads and inserts the correct glue and
penalties between nodes.

\Y\P\D \37$\\{new\_hlist}(\#)\S\\{mem}[\\{nucleus}(\#)].\\{int}$\C{the
translation of an mlist}\par
\fi

\M726. Here is the overall plan of \\{mlist\_to\_hlist}, and the list of its
local variables.

\Y\P\D \37$\\{done\_with\_noad}=80$\C{go here when a noad has been fully
translated}\par
\P\D \37$\\{done\_with\_node}=81$\C{go here when a node has been fully
converted}\par
\P\D \37$\\{check\_dimensions}=82$\C{go here to update \\{max\_h} and \\{max%
\_d}}\par
\P\D \37$\\{delete\_q}=83$\C{go here to delete \|q and move to the next node}%
\par
\Y\P\hbox{\4}\X734:Declare math construction procedures\X \6
\4\&{procedure}\1\  \37\\{mlist\_to\_hlist};\6
\4\&{label} \37$\\{reswitch},\39\\{check\_dimensions},\39\\{done\_with\_noad},%
\39\\{done\_with\_node},\39\\{delete\_q},\39\\{done}$;\6
\4\&{var} \37\\{mlist}: \37\\{pointer};\C{beginning of the given list}\6
\\{penalties}: \37\\{boolean};\C{should penalty nodes be inserted?}\6
\\{style}: \37\\{small\_number};\C{the given style}\6
\\{save\_style}: \37\\{small\_number};\C{holds \\{cur\_style} during recursion}%
\6
\|q: \37\\{pointer};\C{runs through the mlist}\6
\|r: \37\\{pointer};\C{the most recent noad preceding \|q}\6
\\{r\_type}: \37\\{small\_number};\C{the \\{type} of noad \|r, or \\{op\_noad}
if $\|r=\\{null}$}\6
\|t: \37\\{small\_number};\C{the effective \\{type} of noad \|q during the
second pass}\6
$\|p,\39\|x,\39\|y,\39\|z$: \37\\{pointer};\C{temporary registers for list
construction}\6
\\{pen}: \37\\{integer};\C{a penalty to be inserted}\6
\|s: \37\\{small\_number};\C{the size of a noad to be deleted}\6
$\\{max\_h},\39\\{max\_d}$: \37\\{scaled};\C{maximum height and depth of the
list translated so far}\6
\\{delta}: \37\\{scaled};\C{offset between subscript and superscript}\2\6
\&{begin} \37$\\{mlist}\K\\{cur\_mlist}$;\5
$\\{penalties}\K\\{mlist\_penalties}$;\5
$\\{style}\K\\{cur\_style}$;\C{tuck global parameters away as local variables}\6
$\|q\K\\{mlist}$;\5
$\|r\K\\{null}$;\5
$\\{r\_type}\K\\{op\_noad}$;\5
$\\{max\_h}\K0$;\5
$\\{max\_d}\K0$;\5
\X703:Set up the values of \\{cur\_size} and \\{cur\_mu}, based on \\{cur%
\_style}\X;\6
\&{while} $\|q\I\\{null}$ \1\&{do}\5
\X727:Process node-or-noad \|q as much as possible in preparation for the
second pass of \\{mlist\_to\_hlist}, then move to the next item in the mlist\X;%
\2\6
\X729:Convert \(a)a final \\{bin\_noad} to an \\{ord\_noad}\X;\6
\X760:Make a second pass over the mlist, removing all noads and inserting the
proper spacing and penalties\X;\6
\&{end};\par
\fi

\M727. We use the fact that no character nodes appear in an mlist, hence
the field $\\{type}(\|q)$ is always present.

\Y\P$\4\X727:Process node-or-noad \|q as much as possible in preparation for
the second pass of \\{mlist\_to\_hlist}, then move to the next item in the
mlist\X\S$\6
\&{begin} \37\X728:Do first-pass processing based on $\\{type}(\|q)$; \&{goto} %
\\{done\_with\_noad} if a noad has been fully processed, \&{goto} \\{check%
\_dimensions} if it has been translated into $\\{new\_hlist}(\|q)$, or \&{goto}
\\{done\_with\_node} if a node has been fully processed\X;\6
\4\\{check\_dimensions}: \37$\|z\K\\{hpack}(\\{new\_hlist}(\|q),\39%
\\{natural})$;\6
\&{if} $\\{height}(\|z)>\\{max\_h}$ \1\&{then}\5
$\\{max\_h}\K\\{height}(\|z)$;\2\6
\&{if} $\\{depth}(\|z)>\\{max\_d}$ \1\&{then}\5
$\\{max\_d}\K\\{depth}(\|z)$;\2\6
$\\{free\_node}(\|z,\39\\{box\_node\_size})$;\6
\4\\{done\_with\_noad}: \37$\|r\K\|q$;\5
$\\{r\_type}\K\\{type}(\|r)$;\6
\4\\{done\_with\_node}: \37$\|q\K\\{link}(\|q)$;\6
\&{end}\par
\U section~726.\fi

\M728. One of the things we must do on the first pass is change a \\{bin\_noad}
to
an \\{ord\_noad} if the \\{bin\_noad} is not in the context of a binary
operator.
The values of \|r and \\{r\_type} make this fairly easy.

\Y\P$\4\X728:Do first-pass processing based on $\\{type}(\|q)$; \&{goto} %
\\{done\_with\_noad} if a noad has been fully processed, \&{goto} \\{check%
\_dimensions} if it has been translated into $\\{new\_hlist}(\|q)$, or \&{goto}
\\{done\_with\_node} if a node has been fully processed\X\S$\6
\4\\{reswitch}: \37$\\{delta}\K0$;\6
\&{case} $\\{type}(\|q)$ \1\&{of}\6
\4\\{bin\_noad}: \37\&{case} $\\{r\_type}$ \1\&{of}\6
\4$\\{bin\_noad},\39\\{op\_noad},\39\\{rel\_noad},\39\\{open\_noad},\39\\{punct%
\_noad},\39\\{left\_noad}$: \37\&{begin} \37$\\{type}(\|q)\K\\{ord\_noad}$;\5
\&{goto} \37\\{reswitch};\6
\&{end};\6
\4\&{othercases} \37\\{do\_nothing}\2\6
\&{endcases};\6
\4$\\{rel\_noad},\39\\{close\_noad},\39\\{punct\_noad},\39\\{right\_noad}$: \37%
\&{begin} \37\hbox{}\6
\X729:Convert \(a)a final \\{bin\_noad} to an \\{ord\_noad}\X;\6
\&{if} $\\{type}(\|q)=\\{right\_noad}$ \1\&{then}\5
\&{goto} \37\\{done\_with\_noad};\2\6
\&{end};\6
\hbox{\4}\X733:Cases for noads that can follow a \\{bin\_noad}\X\6
\hbox{\4}\X730:Cases for nodes that can appear in an mlist, after which we %
\&{goto} \\{done\_with\_node}\X\6
\4\&{othercases} \37$\\{confusion}(\.{"mlist1"})$\2\6
\&{endcases};\6
\X754:Convert \(n)$\\{nucleus}(\|q)$ to an hlist and attach the
sub/superscripts\X\par
\U section~727.\fi

\M729. \P$\X729:Convert \(a)a final \\{bin\_noad} to an \\{ord\_noad}\X\S$\6
\&{if} $\\{r\_type}=\\{bin\_noad}$ \1\&{then}\5
$\\{type}(\|r)\K\\{ord\_noad}$\2\par
\U sections~726 and~728.\fi

\M730. \P$\X730:Cases for nodes that can appear in an mlist, after which we %
\&{goto} \\{done\_with\_node}\X\S$\6
\4\\{style\_node}: \37\&{begin} \37$\\{cur\_style}\K\\{subtype}(\|q)$;\5
\X703:Set up the values of \\{cur\_size} and \\{cur\_mu}, based on \\{cur%
\_style}\X;\6
\&{goto} \37\\{done\_with\_node};\6
\&{end};\6
\4\\{choice\_node}: \37\X731:Change this node to a style node followed by the
correct choice, then \&{goto} \\{done\_with\_node}\X;\6
\4$\\{ins\_node},\39\\{mark\_node},\39\\{adjust\_node},\39\\{whatsit\_node},\39%
\\{penalty\_node},\39\\{disc\_node}$: \37\&{goto} \37\\{done\_with\_node};\6
\4\\{rule\_node}: \37\&{begin} \37\&{if} $\\{height}(\|q)>\\{max\_h}$ \1%
\&{then}\5
$\\{max\_h}\K\\{height}(\|q)$;\2\6
\&{if} $\\{depth}(\|q)>\\{max\_d}$ \1\&{then}\5
$\\{max\_d}\K\\{depth}(\|q)$;\2\6
\&{goto} \37\\{done\_with\_node};\6
\&{end};\6
\4\\{glue\_node}: \37\&{begin} \37\X732:Convert \(m)math glue to ordinary glue%
\X;\6
\&{goto} \37\\{done\_with\_node};\6
\&{end};\6
\4\\{kern\_node}: \37\&{begin} \37$\\{math\_kern}(\|q,\39\\{cur\_mu})$;\5
\&{goto} \37\\{done\_with\_node};\6
\&{end};\par
\U section~728.\fi

\M731. \P\D \37$\\{choose\_mlist}(\#)\S$\1\6
\&{begin} \37$\|p\K\#(\|q)$;\5
$\#(\|q)\K\\{null}$;\ \&{end}\2\par
\Y\P$\4\X731:Change this node to a style node followed by the correct choice,
then \&{goto} \\{done\_with\_node}\X\S$\6
\&{begin} \37\&{case} $\\{cur\_style}\mathbin{\&{div}}2$ \1\&{of}\6
\40: \37$\\{choose\_mlist}(\\{display\_mlist})$;\C{$\\{display\_style}=0$}\6
\41: \37$\\{choose\_mlist}(\\{text\_mlist})$;\C{$\\{text\_style}=2$}\6
\42: \37$\\{choose\_mlist}(\\{script\_mlist})$;\C{$\\{script\_style}=4$}\6
\43: \37$\\{choose\_mlist}(\\{script\_script\_mlist})$;\C{$\\{script\_script%
\_style}=6$}\2\6
\&{end};\C{there are no other cases}\6
$\\{flush\_node\_list}(\\{display\_mlist}(\|q))$;\5
$\\{flush\_node\_list}(\\{text\_mlist}(\|q))$;\5
$\\{flush\_node\_list}(\\{script\_mlist}(\|q))$;\5
$\\{flush\_node\_list}(\\{script\_script\_mlist}(\|q))$;\6
$\\{type}(\|q)\K\\{style\_node}$;\5
$\\{subtype}(\|q)\K\\{cur\_style}$;\5
$\\{width}(\|q)\K0$;\5
$\\{depth}(\|q)\K0$;\6
\&{if} $\|p\I\\{null}$ \1\&{then}\6
\&{begin} \37$\|z\K\\{link}(\|q)$;\5
$\\{link}(\|q)\K\|p$;\6
\&{while} $\\{link}(\|p)\I\\{null}$ \1\&{do}\5
$\|p\K\\{link}(\|p)$;\2\6
$\\{link}(\|p)\K\|z$;\6
\&{end};\2\6
\&{goto} \37\\{done\_with\_node};\6
\&{end}\par
\U section~730.\fi

\M732. Conditional math glue (`\.{\\nonscript}') results in a \\{glue\_node}
pointing to \\{zero\_glue}, with $\\{subtype}(\|q)=\\{cond\_math\_glue}$; in
such a case
the node following will be eliminated if it is a glue or kern node and if the
current size is different from \\{text\_size}. Unconditional math glue
(`\.{\\muskip}') is converted to normal glue by multiplying the dimensions
by \\{cur\_mu}.

\Y\P$\4\X732:Convert \(m)math glue to ordinary glue\X\S$\6
\&{if} $\\{subtype}(\|q)=\\{mu\_glue}$ \1\&{then}\6
\&{begin} \37$\|x\K\\{glue\_ptr}(\|q)$;\5
$\|y\K\\{math\_glue}(\|x,\39\\{cur\_mu})$;\5
$\\{delete\_glue\_ref}(\|x)$;\5
$\\{glue\_ptr}(\|q)\K\|y$;\5
$\\{subtype}(\|q)\K\\{normal}$;\6
\&{end}\6
\4\&{else} \&{if} $(\\{cur\_size}\I\\{text\_size})\W(\\{subtype}(\|q)=\\{cond%
\_math\_glue})$ \1\&{then}\6
\&{begin} \37$\|p\K\\{link}(\|q)$;\6
\&{if} $\|p\I\\{null}$ \1\&{then}\6
\&{if} $(\\{type}(\|p)=\\{glue\_node})\V(\\{type}(\|p)=\\{kern\_node})$ \1%
\&{then}\6
\&{begin} \37$\\{link}(\|q)\K\\{link}(\|p)$;\5
$\\{link}(\|p)\K\\{null}$;\5
$\\{flush\_node\_list}(\|p)$;\6
\&{end};\2\2\6
\&{end}\2\2\par
\U section~730.\fi

\M733. \P$\X733:Cases for noads that can follow a \\{bin\_noad}\X\S$\6
\4\\{left\_noad}: \37\&{goto} \37\\{done\_with\_noad};\6
\4\\{fraction\_noad}: \37\&{begin} \37$\\{make\_fraction}(\|q)$;\5
\&{goto} \37\\{check\_dimensions};\6
\&{end};\6
\4\\{op\_noad}: \37\&{begin} \37$\\{delta}\K\\{make\_op}(\|q)$;\6
\&{if} $\\{subtype}(\|q)=\\{limits}$ \1\&{then}\5
\&{goto} \37\\{check\_dimensions};\2\6
\&{end};\6
\4\\{ord\_noad}: \37$\\{make\_ord}(\|q)$;\6
\4$\\{open\_noad},\39\\{inner\_noad}$: \37\\{do\_nothing};\6
\4\\{radical\_noad}: \37$\\{make\_radical}(\|q)$;\6
\4\\{over\_noad}: \37$\\{make\_over}(\|q)$;\6
\4\\{under\_noad}: \37$\\{make\_under}(\|q)$;\6
\4\\{accent\_noad}: \37$\\{make\_math\_accent}(\|q)$;\6
\4\\{vcenter\_noad}: \37$\\{make\_vcenter}(\|q)$;\par
\U section~728.\fi

\M734. Most of the actual construction work of \\{mlist\_to\_hlist} is done
by procedures like \\{make\_fraction}, \\{make\_radical}, etc. To illustrate
the general setup of such procedures, let's begin with a couple of
simple ones.

\Y\P$\4\X734:Declare math construction procedures\X\S$\6
\4\&{procedure}\1\  \37$\\{make\_over}(\|q:\\{pointer})$;\2\6
\&{begin} \37$\\{info}(\\{nucleus}(\|q))\K\30\\{overbar}(\\{clean\_box}(%
\\{nucleus}(\|q),\39\\{cramped\_style}(\\{cur\_style})),\39\303\ast\\{default%
\_rule\_thickness},\39\\{default\_rule\_thickness})$;\5
$\\{math\_type}(\\{nucleus}(\|q))\K\\{sub\_box}$;\6
\&{end};\par
\A sections~735, 736, 737, 738, 743, 749, 752, 756, and~762.
\U section~726.\fi

\M735. \P$\X734:Declare math construction procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{make\_under}(\|q:\\{pointer})$;\6
\4\&{var} \37$\|p,\39\|x,\39\|y$: \37\\{pointer};\C{temporary registers for box
construction}\6
\\{delta}: \37\\{scaled};\C{overall height plus depth}\2\6
\&{begin} \37$\|x\K\\{clean\_box}(\\{nucleus}(\|q),\39\\{cur\_style})$;\5
$\|p\K\\{new\_kern}(3\ast\\{default\_rule\_thickness})$;\5
$\\{link}(\|x)\K\|p$;\5
$\\{link}(\|p)\K\\{fraction\_rule}(\\{default\_rule\_thickness})$;\5
$\|y\K\\{vpack}(\|x,\39\\{natural})$;\5
$\\{delta}\K\\{height}(\|y)+\\{depth}(\|y)+\\{default\_rule\_thickness}$;\5
$\\{height}(\|y)\K\\{height}(\|x)$;\5
$\\{depth}(\|y)\K\\{delta}-\\{height}(\|y)$;\5
$\\{info}(\\{nucleus}(\|q))\K\|y$;\5
$\\{math\_type}(\\{nucleus}(\|q))\K\\{sub\_box}$;\6
\&{end};\par
\fi

\M736. \P$\X734:Declare math construction procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{make\_vcenter}(\|q:\\{pointer})$;\6
\4\&{var} \37\|v: \37\\{pointer};\C{the box that should be centered vertically}%
\6
\\{delta}: \37\\{scaled};\C{its height plus depth}\2\6
\&{begin} \37$\|v\K\\{info}(\\{nucleus}(\|q))$;\6
\&{if} $\\{type}(\|v)\I\\{vlist\_node}$ \1\&{then}\5
$\\{confusion}(\.{"vcenter"})$;\2\6
$\\{delta}\K\\{height}(\|v)+\\{depth}(\|v)$;\5
$\\{height}(\|v)\K\\{axis\_height}(\\{cur\_size})+\\{half}(\\{delta})$;\5
$\\{depth}(\|v)\K\\{delta}-\\{height}(\|v)$;\6
\&{end};\par
\fi

\M737. According to the rules in the \.{DVI} file specifications, we ensure
alignment
between a square root sign and the rule above its nucleus by assuming that the
baseline of the square-root symbol is the same as the bottom of the rule. The
height of the square-root symbol will be the thickness of the rule, and the
depth of the square-root symbol should exceed or equal the height-plus-depth
of the nucleus plus a certain minimum clearance~\\{clr}. The symbol will be
placed so that the actual clearance is \\{clr} plus half the excess.

\Y\P$\4\X734:Declare math construction procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{make\_radical}(\|q:\\{pointer})$;\6
\4\&{var} \37$\|x,\39\|y$: \37\\{pointer};\C{temporary registers for box
construction}\6
$\\{delta},\39\\{clr}$: \37\\{scaled};\C{dimensions involved in the
calculation}\2\6
\&{begin} \37$\|x\K\\{clean\_box}(\\{nucleus}(\|q),\39\\{cramped\_style}(\\{cur%
\_style}))$;\6
\&{if} $\\{cur\_style}<\\{text\_style}$ \1\&{then}\C{display style}\6
$\\{clr}\K\\{default\_rule\_thickness}+(\\{abs}(\\{math\_x\_height}(\\{cur%
\_size}))\mathbin{\&{div}}4)$\6
\4\&{else} \&{begin} \37$\\{clr}\K\\{default\_rule\_thickness}$;\5
$\\{clr}\K\\{clr}+(\\{abs}(\\{clr})\mathbin{\&{div}}4)$;\6
\&{end};\2\6
$\|y\K\\{var\_delimiter}(\\{left\_delimiter}(\|q),\39\\{cur\_size},\39%
\\{height}(\|x)+\\{depth}(\|x)+\\{clr}+\\{default\_rule\_thickness})$;\5
$\\{delta}\K\\{depth}(\|y)-(\\{height}(\|x)+\\{depth}(\|x)+\\{clr})$;\6
\&{if} $\\{delta}>0$ \1\&{then}\5
$\\{clr}\K\\{clr}+\\{half}(\\{delta})$;\C{increase the actual clearance}\2\6
$\\{shift\_amount}(\|y)\K-(\\{height}(\|x)+\\{clr})$;\5
$\\{link}(\|y)\K\\{overbar}(\|x,\39\\{clr},\39\\{height}(\|y))$;\5
$\\{info}(\\{nucleus}(\|q))\K\\{hpack}(\|y,\39\\{natural})$;\5
$\\{math\_type}(\\{nucleus}(\|q))\K\\{sub\_box}$;\6
\&{end};\par
\fi

\M738. Slants are not considered when placing accents in math mode. The
accenter is
centered over the accentee, and the accent width is treated as zero with
respect to the size of the final box.

\Y\P$\4\X734:Declare math construction procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{make\_math\_accent}(\|q:\\{pointer})$;\6
\4\&{label} \37$\\{done},\39\\{done1}$;\6
\4\&{var} \37$\|p,\39\|x,\39\|y$: \37\\{pointer};\C{temporary registers for box
construction}\6
\|a: \37\\{integer};\C{address of lig/kern instruction}\6
\|c: \37\\{quarterword};\C{accent character}\6
\|f: \37\\{internal\_font\_number};\C{its font}\6
\|i: \37\\{four\_quarters};\C{its \\{char\_info}}\6
\|s: \37\\{scaled};\C{amount to skew the accent to the right}\6
\|h: \37\\{scaled};\C{height of character being accented}\6
\\{delta}: \37\\{scaled};\C{space to remove between accent and accentee}\6
\|w: \37\\{scaled};\C{width of the accentee, not including sub/superscripts}\2\6
\&{begin} \37$\\{fetch}(\\{accent\_chr}(\|q))$;\6
\&{if} $\\{char\_exists}(\\{cur\_i})$ \1\&{then}\6
\&{begin} \37$\|i\K\\{cur\_i}$;\5
$\|c\K\\{cur\_c}$;\5
$\|f\K\\{cur\_f}$;\6
\X741:Compute the amount of skew\X;\6
$\|x\K\\{clean\_box}(\\{nucleus}(\|q),\39\\{cramped\_style}(\\{cur\_style}))$;\5
$\|w\K\\{width}(\|x)$;\5
$\|h\K\\{height}(\|x)$;\5
\X740:Switch to a larger accent if available and appropriate\X;\6
\&{if} $\|h<\\{x\_height}(\|f)$ \1\&{then}\5
$\\{delta}\K\|h$\ \&{else} $\\{delta}\K\\{x\_height}(\|f)$;\2\6
\&{if} $(\\{math\_type}(\\{supscr}(\|q))\I\\{empty})\V(\\{math\_type}(%
\\{subscr}(\|q))\I\\{empty})$ \1\&{then}\6
\&{if} $\\{math\_type}(\\{nucleus}(\|q))=\\{math\_char}$ \1\&{then}\5
\X742:Swap the subscript and superscript into box \|x\X;\2\2\6
$\|y\K\\{char\_box}(\|f,\39\|c)$;\5
$\\{shift\_amount}(\|y)\K\|s+\\{half}(\|w-\\{width}(\|y))$;\5
$\\{width}(\|y)\K0$;\5
$\|p\K\\{new\_kern}(-\\{delta})$;\5
$\\{link}(\|p)\K\|x$;\5
$\\{link}(\|y)\K\|p$;\5
$\|y\K\\{vpack}(\|y,\39\\{natural})$;\5
$\\{width}(\|y)\K\\{width}(\|x)$;\6
\&{if} $\\{height}(\|y)<\|h$ \1\&{then}\5
\X739:Make the height of box \|y equal to \|h\X;\2\6
$\\{info}(\\{nucleus}(\|q))\K\|y$;\5
$\\{math\_type}(\\{nucleus}(\|q))\K\\{sub\_box}$;\6
\&{end};\2\6
\&{end};\par
\fi

\M739. \P$\X739:Make the height of box \|y equal to \|h\X\S$\6
\&{begin} \37$\|p\K\\{new\_kern}(\|h-\\{height}(\|y))$;\5
$\\{link}(\|p)\K\\{list\_ptr}(\|y)$;\5
$\\{list\_ptr}(\|y)\K\|p$;\5
$\\{height}(\|y)\K\|h$;\6
\&{end}\par
\U section~738.\fi

\M740. \P$\X740:Switch to a larger accent if available and appropriate\X\S$\6
\~ \1\&{loop}\ \&{begin} \37\&{if} $\\{char\_tag}(\|i)\I\\{list\_tag}$ \1%
\&{then}\5
\&{goto} \37\\{done};\2\6
$\|y\K\\{rem\_byte}(\|i)$;\5
$\|i\K\\{char\_info}(\|f)(\|y)$;\6
\&{if} $\\{char\_width}(\|f)(\|i)>\|w$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
$\|c\K\|y$;\6
\&{end};\2\6
\4\\{done}: \37\par
\U section~738.\fi

\M741. \P$\X741:Compute the amount of skew\X\S$\6
$\|s\K0$;\6
\&{if} $\\{math\_type}(\\{nucleus}(\|q))=\\{math\_char}$ \1\&{then}\6
\&{begin} \37$\\{fetch}(\\{nucleus}(\|q))$;\6
\&{if} $\\{char\_tag}(\\{cur\_i})=\\{lig\_tag}$ \1\&{then}\6
\&{begin} \37$\|a\K\\{lig\_kern\_start}(\\{cur\_f})(\\{cur\_i})$;\6
\1\&{repeat} \37$\\{cur\_i}\K\\{font\_info}[\|a].\\{qqqq}$;\6
\&{if} $\\{qo}(\\{next\_char}(\\{cur\_i}))=\\{skew\_char}[\\{cur\_f}]$ \1%
\&{then}\6
\&{begin} \37\&{if} $\\{op\_bit}(\\{cur\_i})\G\\{kern\_flag}$ \1\&{then}\5
$\|s\K\\{char\_kern}(\\{cur\_f})(\\{cur\_i})$;\2\6
\&{goto} \37\\{done1};\6
\&{end};\2\6
$\\{incr}(\|a)$;\6
\4\&{until}\5
$\\{stop\_bit}(\\{cur\_i})\G\\{stop\_flag}$;\2\6
\&{end};\2\6
\&{end};\2\6
\4\\{done1}: \37\par
\U section~738.\fi

\M742. \P$\X742:Swap the subscript and superscript into box \|x\X\S$\6
\&{begin} \37$\\{flush\_node\_list}(\|x)$;\5
$\|x\K\\{new\_noad}$;\5
$\\{mem}[\\{nucleus}(\|x)]\K\\{mem}[\\{nucleus}(\|q)]$;\5
$\\{mem}[\\{supscr}(\|x)]\K\\{mem}[\\{supscr}(\|q)]$;\5
$\\{mem}[\\{subscr}(\|x)]\K\\{mem}[\\{subscr}(\|q)]$;\6
$\\{mem}[\\{supscr}(\|q)].\\{hh}\K\\{empty\_field}$;\5
$\\{mem}[\\{subscr}(\|q)].\\{hh}\K\\{empty\_field}$;\6
$\\{math\_type}(\\{nucleus}(\|q))\K\\{sub\_mlist}$;\5
$\\{info}(\\{nucleus}(\|q))\K\|x$;\5
$\|x\K\\{clean\_box}(\\{nucleus}(\|q),\39\\{cur\_style})$;\5
$\\{delta}\K\\{delta}+\\{height}(\|x)-\|h$;\5
$\|h\K\\{height}(\|x)$;\6
\&{end}\par
\U section~738.\fi

\M743. The \\{make\_fraction} procedure is a bit different because it sets
$\\{new\_hlist}(\|q)$ directly rather than making a sub-box.

\Y\P$\4\X734:Declare math construction procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{make\_fraction}(\|q:\\{pointer})$;\6
\4\&{var} \37$\|p,\39\|v,\39\|x,\39\|y,\39\|z$: \37\\{pointer};\C{temporary
registers for box construction}\6
$\\{delta},\39\\{delta1},\39\\{delta2},\39\\{shift\_up},\39\\{shift\_down},\39%
\\{clr}$: \37\\{scaled};\C{dimensions for box calculations}\2\6
\&{begin} \37\&{if} $\\{thickness}(\|q)=\\{default\_code}$ \1\&{then}\5
$\\{thickness}(\|q)\K\\{default\_rule\_thickness}$;\2\6
\X744:Create equal-width boxes \|x and \|z for the numerator and denominator,
and compute the default amounts \\{shift\_up} and \\{shift\_down} by which they
are displaced from the baseline\X;\6
\&{if} $\\{thickness}(\|q)=0$ \1\&{then}\5
\X745:Adjust \(s)\\{shift\_up} and \\{shift\_down} for the case of no fraction
line\X\6
\4\&{else} \X746:Adjust \(s)\\{shift\_up} and \\{shift\_down} for the case of a
fraction line\X;\2\6
\X747:Construct a vlist box for the fraction, according to \\{shift\_up} and %
\\{shift\_down}\X;\6
\X748:Put the \(f)fraction into a box with its delimiters, and make $\\{new%
\_hlist}(\|q)$ point to it\X;\6
\&{end};\par
\fi

\M744. \P$\X744:Create equal-width boxes \|x and \|z for the numerator and
denominator, and compute the default amounts \\{shift\_up} and \\{shift\_down}
by which they are displaced from the baseline\X\S$\6
$\|x\K\\{clean\_box}(\\{numerator}(\|q),\39\\{num\_style}(\\{cur\_style}))$;\5
$\|z\K\\{clean\_box}(\\{denominator}(\|q),\39\\{denom\_style}(\\{cur%
\_style}))$;\6
\&{if} $\\{width}(\|x)<\\{width}(\|z)$ \1\&{then}\5
$\|x\K\\{rebox}(\|x,\39\\{width}(\|z))$\6
\4\&{else} $\|z\K\\{rebox}(\|z,\39\\{width}(\|x))$;\2\6
\&{if} $\\{cur\_style}<\\{text\_style}$ \1\&{then}\C{text style}\6
\&{begin} \37$\\{shift\_up}\K\\{num1}(\\{cur\_size})$;\5
$\\{shift\_down}\K\\{denom1}(\\{cur\_size})$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{shift\_down}\K\\{denom2}(\\{cur\_size})$;\6
\&{if} $\\{thickness}(\|q)\I0$ \1\&{then}\5
$\\{shift\_up}\K\\{num2}(\\{cur\_size})$\6
\4\&{else} $\\{shift\_up}\K\\{num3}(\\{cur\_size})$;\2\6
\&{end}\2\par
\U section~743.\fi

\M745. The numerator and denominator must be separated by a certain minimum
clearance, called \\{clr} in the following program. The difference between
\\{clr} and the actual clearance is 2\\{delta}.

\Y\P$\4\X745:Adjust \(s)\\{shift\_up} and \\{shift\_down} for the case of no
fraction line\X\S$\6
\&{begin} \37\&{if} $\\{cur\_style}<\\{text\_style}$ \1\&{then}\5
$\\{clr}\K7\ast\\{default\_rule\_thickness}$\6
\4\&{else} $\\{clr}\K3\ast\\{default\_rule\_thickness}$;\2\6
$\\{delta}\K\\{half}(\\{clr}-((\\{shift\_up}-\\{depth}(\|x))-(\\{height}(\|z)-%
\\{shift\_down})))$;\6
\&{if} $\\{delta}>0$ \1\&{then}\6
\&{begin} \37$\\{shift\_up}\K\\{shift\_up}+\\{delta}$;\5
$\\{shift\_down}\K\\{shift\_down}+\\{delta}$;\6
\&{end};\2\6
\&{end}\par
\U section~743.\fi

\M746. In the case of a fraction line, the minimum clearance depends on the
actual
thickness of the line.

\Y\P$\4\X746:Adjust \(s)\\{shift\_up} and \\{shift\_down} for the case of a
fraction line\X\S$\6
\&{begin} \37\&{if} $\\{cur\_style}<\\{text\_style}$ \1\&{then}\5
$\\{clr}\K3\ast\\{thickness}(\|q)$\6
\4\&{else} $\\{clr}\K\\{thickness}(\|q)$;\2\6
$\\{delta}\K\\{half}(\\{thickness}(\|q))$;\5
$\\{delta1}\K\\{clr}-((\\{shift\_up}-\\{depth}(\|x))-(\\{axis\_height}(\\{cur%
\_size})+\\{delta}))$;\5
$\\{delta2}\K\\{clr}-((\\{axis\_height}(\\{cur\_size})-\\{delta})-(\\{height}(%
\|z)-\\{shift\_down}))$;\6
\&{if} $\\{delta1}>0$ \1\&{then}\5
$\\{shift\_up}\K\\{shift\_up}+\\{delta1}$;\2\6
\&{if} $\\{delta2}>0$ \1\&{then}\5
$\\{shift\_down}\K\\{shift\_down}+\\{delta2}$;\2\6
\&{end}\par
\U section~743.\fi

\M747. \P$\X747:Construct a vlist box for the fraction, according to \\{shift%
\_up} and \\{shift\_down}\X\S$\6
$\|v\K\\{new\_null\_box}$;\5
$\\{type}(\|v)\K\\{vlist\_node}$;\5
$\\{height}(\|v)\K\\{shift\_up}+\\{height}(\|x)$;\5
$\\{depth}(\|v)\K\\{depth}(\|z)+\\{shift\_down}$;\5
$\\{width}(\|v)\K\\{width}(\|x)$;\C{this also equals $\\{width}(\|z)$}\6
\&{if} $\\{thickness}(\|q)=0$ \1\&{then}\6
\&{begin} \37$\|p\K\\{new\_kern}((\\{shift\_up}-\\{depth}(\|x))-(\\{height}(%
\|z)-\\{shift\_down}))$;\5
$\\{link}(\|p)\K\|z$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\|y\K\\{fraction\_rule}(\\{thickness}(\|q))$;\6
$\|p\K\\{new\_kern}((\\{axis\_height}(\\{cur\_size})-\\{delta})-\30(\\{height}(%
\|z)-\\{shift\_down}))$;\6
$\\{link}(\|y)\K\|p$;\5
$\\{link}(\|p)\K\|z$;\6
$\|p\K\\{new\_kern}((\\{shift\_up}-\\{depth}(\|x))-(\\{axis\_height}(\\{cur%
\_size})+\\{delta}))$;\5
$\\{link}(\|p)\K\|y$;\6
\&{end};\2\6
$\\{link}(\|x)\K\|p$;\5
$\\{list\_ptr}(\|v)\K\|x$\par
\U section~743.\fi

\M748. \P$\X748:Put the \(f)fraction into a box with its delimiters, and make $%
\\{new\_hlist}(\|q)$ point to it\X\S$\6
\&{if} $\\{cur\_style}<\\{text\_style}$ \1\&{then}\5
$\\{delta}\K\\{delim1}(\\{cur\_size})$\6
\4\&{else} $\\{delta}\K\\{delim2}(\\{cur\_size})$;\2\6
$\|x\K\\{var\_delimiter}(\\{left\_delimiter}(\|q),\39\\{cur\_size},\39%
\\{delta})$;\5
$\\{link}(\|x)\K\|v$;\6
$\|z\K\\{var\_delimiter}(\\{right\_delimiter}(\|q),\39\\{cur\_size},\39%
\\{delta})$;\5
$\\{link}(\|v)\K\|z$;\6
$\\{new\_hlist}(\|q)\K\\{hpack}(\|x,\39\\{natural})$\par
\U section~743.\fi

\M749. If the nucleus of an \\{op\_noad} is a single character, it is to be
centered vertically with respect to the axis, after first being enlarged
(via a character list in the font) if we are in display style.  The normal
convention for placing displayed limits is to put them above and below the
operator in display style.

The italic correction is removed from the character if there is a subscript
and the limits are not being displayed. The \\{make\_op}
routine returns the value that should be used as an offset between
subscript and superscript.

After \\{make\_op} has acted, $\\{subtype}(\|q)$ will be \\{limits} if and only
if
the limits have been set above and below the operator. In that case,
$\\{new\_hlist}(\|q)$ will already contain the desired final box.

\Y\P$\4\X734:Declare math construction procedures\X\mathrel{+}\S$\6
\4\&{function}\1\  \37$\\{make\_op}(\|q:\\{pointer})$: \37\\{scaled};\6
\4\&{var} \37\\{delta}: \37\\{scaled};\C{offset between subscript and
superscript}\6
$\|p,\39\|v,\39\|x,\39\|y,\39\|z$: \37\\{pointer};\C{temporary registers for
box construction}\6
$\\{shift\_up},\39\\{shift\_down}$: \37\\{scaled};\C{dimensions for box
calculation}\2\6
\&{begin} \37\&{if} $(\\{subtype}(\|q)=\\{normal})\W(\\{cur\_style}<\\{text%
\_style})$ \1\&{then}\5
$\\{subtype}(\|q)\K\\{limits}$;\2\6
\&{if} $\\{math\_type}(\\{nucleus}(\|q))=\\{math\_char}$ \1\&{then}\6
\&{begin} \37$\\{fetch}(\\{nucleus}(\|q))$;\6
\&{if} $(\\{cur\_style}<\\{text\_style})\W(\\{char\_tag}(\\{cur\_i})=\\{list%
\_tag})$ \1\&{then}\C{make it larger}\6
\&{begin} \37$\\{cur\_c}\K\\{rem\_byte}(\\{cur\_i})$;\5
$\\{character}(\\{nucleus}(\|q))\K\\{cur\_c}$;\5
$\\{cur\_i}\K\\{char\_info}(\\{cur\_f})(\\{cur\_c})$;\6
\&{end};\2\6
$\\{delta}\K\\{char\_italic}(\\{cur\_f})(\\{cur\_i})$;\5
$\|x\K\\{clean\_box}(\\{nucleus}(\|q),\39\\{cur\_style})$;\6
\&{if} $(\\{math\_type}(\\{subscr}(\|q))\I\\{empty})\W(\\{subtype}(\|q)\I%
\\{limits})$ \1\&{then}\5
$\\{width}(\|x)\K\\{width}(\|x)-\\{delta}$;\C{remove italic correction}\2\6
$\\{shift\_amount}(\|x)\K\\{half}(\\{height}(\|x)-\\{depth}(\|x))-\\{axis%
\_height}(\\{cur\_size})$;\C{center vertically}\6
$\\{math\_type}(\\{nucleus}(\|q))\K\\{sub\_box}$;\5
$\\{info}(\\{nucleus}(\|q))\K\|x$;\6
\&{end}\6
\4\&{else} $\\{delta}\K0$;\2\6
\&{if} $\\{subtype}(\|q)=\\{limits}$ \1\&{then}\5
\X750:Construct a box with limits above and below it, skewed by \\{delta}\X;\2\6
$\\{make\_op}\K\\{delta}$;\6
\&{end};\par
\fi

\M750. The following program builds a vlist box \|v for displayed limits. The
width of the box is not affected by the fact that the limits may be skewed.

\Y\P$\4\X750:Construct a box with limits above and below it, skewed by %
\\{delta}\X\S$\6
\&{begin} \37$\|x\K\\{clean\_box}(\\{supscr}(\|q),\39\\{sup\_style}(\\{cur%
\_style}))$;\5
$\|y\K\\{clean\_box}(\\{nucleus}(\|q),\39\\{cur\_style})$;\5
$\|z\K\\{clean\_box}(\\{subscr}(\|q),\39\\{sub\_style}(\\{cur\_style}))$;\5
$\|v\K\\{new\_null\_box}$;\5
$\\{type}(\|v)\K\\{vlist\_node}$;\5
$\\{width}(\|v)\K\\{width}(\|y)$;\6
\&{if} $\\{width}(\|x)>\\{width}(\|v)$ \1\&{then}\5
$\\{width}(\|v)\K\\{width}(\|x)$;\2\6
\&{if} $\\{width}(\|z)>\\{width}(\|v)$ \1\&{then}\5
$\\{width}(\|v)\K\\{width}(\|z)$;\2\6
$\|x\K\\{rebox}(\|x,\39\\{width}(\|v))$;\5
$\|y\K\\{rebox}(\|y,\39\\{width}(\|v))$;\5
$\|z\K\\{rebox}(\|z,\39\\{width}(\|v))$;\6
$\\{shift\_amount}(\|x)\K\\{half}(\\{delta})$;\5
$\\{shift\_amount}(\|z)\K-\\{shift\_amount}(\|x)$;\5
$\\{height}(\|v)\K\\{height}(\|y)$;\5
$\\{depth}(\|v)\K\\{depth}(\|y)$;\5
\X751:Attach the limits to \|y and adjust $\\{height}(\|v)$, $\\{depth}(\|v)$
to account for their presence\X;\6
$\\{new\_hlist}(\|q)\K\|v$;\6
\&{end}\par
\U section~749.\fi

\M751. We use \\{shift\_up} and \\{shift\_down} in the following program for
the
amount of glue between the displayed operator \|y and its limits \|x and
\|z. The vlist inside box \|v will consist of \|x followed by \|y followed
by \|z, with kern nodes for the spaces between and around them.

\Y\P$\4\X751:Attach the limits to \|y and adjust $\\{height}(\|v)$, $\\{depth}(%
\|v)$ to account for their presence\X\S$\6
\&{if} $\\{math\_type}(\\{supscr}(\|q))=\\{empty}$ \1\&{then}\6
\&{begin} \37$\\{free\_node}(\|x,\39\\{box\_node\_size})$;\5
$\\{list\_ptr}(\|v)\K\|y$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{shift\_up}\K\\{big\_op\_spacing3}-\\{depth}(\|x)$;\6
\&{if} $\\{shift\_up}<\\{big\_op\_spacing1}$ \1\&{then}\5
$\\{shift\_up}\K\\{big\_op\_spacing1}$;\2\6
$\|p\K\\{new\_kern}(\\{shift\_up})$;\5
$\\{link}(\|p)\K\|y$;\5
$\\{link}(\|x)\K\|p$;\6
$\|p\K\\{new\_kern}(\\{big\_op\_spacing5})$;\5
$\\{link}(\|p)\K\|x$;\5
$\\{list\_ptr}(\|v)\K\|p$;\5
$\\{height}(\|v)\K\\{height}(\|v)+\\{big\_op\_spacing5}+\\{height}(\|x)+%
\\{depth}(\|x)+\\{shift\_up}$;\6
\&{end};\2\6
\&{if} $\\{math\_type}(\\{subscr}(\|q))=\\{empty}$ \1\&{then}\5
$\\{free\_node}(\|z,\39\\{box\_node\_size})$\6
\4\&{else} \&{begin} \37$\\{shift\_down}\K\\{big\_op\_spacing4}-\\{height}(%
\|z)$;\6
\&{if} $\\{shift\_down}<\\{big\_op\_spacing2}$ \1\&{then}\5
$\\{shift\_down}\K\\{big\_op\_spacing2}$;\2\6
$\|p\K\\{new\_kern}(\\{shift\_down})$;\5
$\\{link}(\|y)\K\|p$;\5
$\\{link}(\|p)\K\|z$;\6
$\|p\K\\{new\_kern}(\\{big\_op\_spacing5})$;\5
$\\{link}(\|z)\K\|p$;\5
$\\{depth}(\|v)\K\\{depth}(\|v)+\\{big\_op\_spacing5}+\\{height}(\|z)+%
\\{depth}(\|z)+\\{shift\_down}$;\6
\&{end}\2\par
\U section~750.\fi

\M752. A ligature found in a math formula does not create a \\{ligature\_node},
because
there is no question of hyphenation afterwards; the ligature will simply be
stored in an ordinary \\{char\_node}, after residing in an \\{ord\_noad}.

The \\{math\_type} is converted to \\{math\_text\_char} here if we would not
want to
apply an italic correction to the current character unless it belongs
to a math font (i.e., a font with $\\{space}=0$).

\Y\P$\4\X734:Declare math construction procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{make\_ord}(\|q:\\{pointer})$;\6
\4\&{label} \37$\\{restart},\39\\{exit}$;\6
\4\&{var} \37\|a: \37\\{integer};\C{address of lig/kern instruction}\6
\|p: \37\\{pointer};\C{temporary register for list manipulation}\2\6
\&{begin} \37\\{restart}: \37\hbox{}\6
\&{if} $(\\{math\_type}(\\{subscr}(\|q))=\\{empty})\W(\\{math\_type}(%
\\{supscr}(\|q))=\\{empty})\W\30(\\{math\_type}(\\{nucleus}(\|q))=\\{math%
\_char})$ \1\&{then}\6
\&{begin} \37$\|p\K\\{link}(\|q)$;\6
\&{if} $\|p\I\\{null}$ \1\&{then}\6
\&{if} $(\\{type}(\|p)\G\\{ord\_noad})\W(\\{type}(\|p)\L\\{punct\_noad})$ \1%
\&{then}\6
\&{if} $\\{math\_type}(\\{nucleus}(\|p))=\\{math\_char}$ \1\&{then}\6
\&{if} $\\{fam}(\\{nucleus}(\|p))=\\{fam}(\\{nucleus}(\|q))$ \1\&{then}\6
\&{begin} \37$\\{math\_type}(\\{nucleus}(\|q))\K\\{math\_text\_char}$;\5
$\\{fetch}(\\{nucleus}(\|q))$;\6
\&{if} $\\{char\_tag}(\\{cur\_i})=\\{lig\_tag}$ \1\&{then}\6
\&{begin} \37$\|a\K\\{lig\_kern\_start}(\\{cur\_f})(\\{cur\_i})$;\5
$\\{cur\_c}\K\\{character}(\\{nucleus}(\|p))$;\6
\1\&{repeat} \37$\\{cur\_i}\K\\{font\_info}[\|a].\\{qqqq}$;\6
\X753:If instruction \\{cur\_i} is a kern with \\{cur\_c}, attach the kern
after \|q and \&{return}; or if it is a ligature with \\{cur\_c}, combine noads
\|q and \|p and \&{goto} \\{restart}\X;\6
$\\{incr}(\|a)$;\6
\4\&{until}\5
$\\{stop\_bit}(\\{cur\_i})\G\\{stop\_flag}$;\2\6
\&{end};\2\6
\&{end};\2\2\2\2\6
\&{end};\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M753. Note that a ligature between an \\{ord\_noad} and another kind of noad
is replaced by an \\{ord\_noad}. Presumably a font designer will define such
ligatures only when this convention makes sense.

\Y\P$\4\X753:If instruction \\{cur\_i} is a kern with \\{cur\_c}, attach the
kern after \|q and \&{return}; or if it is a ligature with \\{cur\_c}, combine
noads \|q and \|p and \&{goto} \\{restart}\X\S$\6
\&{if} $\\{next\_char}(\\{cur\_i})=\\{cur\_c}$ \1\&{then}\6
\&{if} $\\{op\_bit}(\\{cur\_i})\G\\{kern\_flag}$ \1\&{then}\6
\&{begin} \37$\|p\K\\{new\_kern}(\\{char\_kern}(\\{cur\_f})(\\{cur\_i}))$;\5
$\\{link}(\|p)\K\\{link}(\|q)$;\5
$\\{link}(\|q)\K\|p$;\5
\&{return};\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{link}(\|q)\K\\{link}(\|p)$;\5
$\\{math\_type}(\\{nucleus}(\|q))\K\\{math\_char}$;\5
$\\{character}(\\{nucleus}(\|q))\K\\{rem\_byte}(\\{cur\_i})$;\6
$\\{mem}[\\{subscr}(\|q)]\K\\{mem}[\\{subscr}(\|p)]$;\5
$\\{mem}[\\{supscr}(\|q)]\K\\{mem}[\\{supscr}(\|p)]$;\5
$\\{free\_node}(\|p,\39\\{noad\_size})$;\5
\&{goto} \37\\{restart};\6
\&{end}\2\2\par
\U section~752.\fi

\M754. When we get to the following part of the program, we have ``fallen
through''
from cases that did not lead to \\{check\_dimensions} or \\{done\_with\_noad}
or
\\{done\_with\_node}. Thus, \|q~points to a noad whose nucleus may need to be
converted to an hlist, and whose subscripts and superscripts need to be
appended if they are present.

If $\\{nucleus}(\|q)$ is not a \\{math\_char}, the variable \\{delta} is the
amount
by which a superscript should be moved right with respect to a subscript
when both are present.

\Y\P$\4\X754:Convert \(n)$\\{nucleus}(\|q)$ to an hlist and attach the
sub/superscripts\X\S$\6
\&{case} $\\{math\_type}(\\{nucleus}(\|q))$ \1\&{of}\6
\4$\\{math\_char},\39\\{math\_text\_char}$: \37\X755:Create a character node %
\|p for $\\{nucleus}(\|q)$, possibly followed by a kern node for the italic
correction, and set \\{delta} to the italic correction if a subscript is
present\X;\6
\4\\{empty}: \37$\|p\K\\{null}$;\6
\4\\{sub\_box}: \37$\|p\K\\{info}(\\{nucleus}(\|q))$;\6
\4\\{sub\_mlist}: \37\&{begin} \37$\\{cur\_mlist}\K\\{info}(\\{nucleus}(\|q))$;%
\5
$\\{save\_style}\K\\{cur\_style}$;\5
$\\{mlist\_penalties}\K\\{false}$;\5
\\{mlist\_to\_hlist};\C{recursive call}\6
$\\{cur\_style}\K\\{save\_style}$;\5
\X703:Set up the values of \\{cur\_size} and \\{cur\_mu}, based on \\{cur%
\_style}\X;\6
$\|p\K\\{hpack}(\\{link}(\\{temp\_head}),\39\\{natural})$;\6
\&{end};\6
\4\&{othercases} \37$\\{confusion}(\.{"mlist2"})$\2\6
\&{endcases};\6
$\\{new\_hlist}(\|q)\K\|p$;\6
\&{if} $(\\{math\_type}(\\{subscr}(\|q))=\\{empty})\W(\\{math\_type}(%
\\{supscr}(\|q))=\\{empty})$ \1\&{then}\5
\&{goto} \37\\{check\_dimensions};\2\6
$\\{make\_scripts}(\|q,\39\\{delta})$\par
\U section~728.\fi

\M755. \P$\X755:Create a character node \|p for $\\{nucleus}(\|q)$, possibly
followed by a kern node for the italic correction, and set \\{delta} to the
italic correction if a subscript is present\X\S$\6
\&{begin} \37$\\{fetch}(\\{nucleus}(\|q))$;\6
\&{if} $\\{char\_exists}(\\{cur\_i})$ \1\&{then}\6
\&{begin} \37$\\{delta}\K\\{char\_italic}(\\{cur\_f})(\\{cur\_i})$;\5
$\|p\K\\{new\_character}(\\{cur\_f},\39\\{qo}(\\{cur\_c}))$;\6
\&{if} $(\\{math\_type}(\\{nucleus}(\|q))=\\{math\_text\_char})\W(\\{space}(%
\\{cur\_f})\I0)$ \1\&{then}\5
$\\{delta}\K0$;\C{no italic correction in mid-word of text font}\2\6
\&{if} $(\\{math\_type}(\\{subscr}(\|q))=\\{empty})\W(\\{delta}\I0)$ \1\&{then}%
\6
\&{begin} \37$\\{link}(\|p)\K\\{new\_kern}(\\{delta})$;\5
$\\{delta}\K0$;\6
\&{end};\2\6
\&{end}\6
\4\&{else} $\|p\K\\{null}$;\2\6
\&{end}\par
\U section~754.\fi

\M756. The purpose of $\\{make\_scripts}(\|q,\\{delta})$ is to attach the
subscript and/or
superscript of noad \|q to the list that starts at $\\{new\_hlist}(\|q)$,
given that subscript and superscript aren't both empty. The superscript
will appear to the right of the subscript by a given distance \\{delta}.

We set \\{shift\_down} and \\{shift\_up} to the minimum amounts to shift the
baseline of subscripts and superscripts based on the given nucleus.

\Y\P$\4\X734:Declare math construction procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{make\_scripts}(\|q:\\{pointer};\,\35\\{delta}:%
\\{scaled})$;\6
\4\&{var} \37$\|p,\39\|x,\39\|y,\39\|z$: \37\\{pointer};\C{temporary registers
for box construction}\6
$\\{shift\_up},\39\\{shift\_down},\39\\{clr}$: \37\\{scaled};\C{dimensions in
the calculation}\6
\|t: \37\\{small\_number};\C{subsidiary size code}\2\6
\&{begin} \37$\|p\K\\{new\_hlist}(\|q)$;\6
\&{if} $\\{is\_char\_node}(\|p)$ \1\&{then}\6
\&{begin} \37$\\{shift\_up}\K0$;\5
$\\{shift\_down}\K0$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\|z\K\\{hpack}(\|p,\39\\{natural})$;\6
\&{if} $\\{cur\_style}<\\{script\_style}$ \1\&{then}\5
$\|t\K\\{script\_size}$\ \&{else} $\|t\K\\{script\_script\_size}$;\2\6
$\\{shift\_up}\K\\{height}(\|z)-\\{sup\_drop}(\|t)$;\5
$\\{shift\_down}\K\\{depth}(\|z)+\\{sub\_drop}(\|t)$;\5
$\\{free\_node}(\|z,\39\\{box\_node\_size})$;\6
\&{end};\2\6
\&{if} $\\{math\_type}(\\{supscr}(\|q))=\\{empty}$ \1\&{then}\5
\X757:Construct a subscript box \|x when there is no superscript\X\6
\4\&{else} \&{begin} \37\X758:Construct a superscript box \|x\X;\6
\&{if} $\\{math\_type}(\\{subscr}(\|q))=\\{empty}$ \1\&{then}\5
$\\{shift\_amount}(\|x)\K-\\{shift\_up}$\6
\4\&{else} \X759:Construct a sub/superscript combination box \|x, with the
superscript offset by \\{delta}\X;\2\6
\&{end};\2\6
\&{if} $\\{new\_hlist}(\|q)=\\{null}$ \1\&{then}\5
$\\{new\_hlist}(\|q)\K\|x$\6
\4\&{else} \&{begin} \37$\|p\K\\{new\_hlist}(\|q)$;\6
\&{while} $\\{link}(\|p)\I\\{null}$ \1\&{do}\5
$\|p\K\\{link}(\|p)$;\2\6
$\\{link}(\|p)\K\|x$;\6
\&{end};\2\6
\&{end};\par
\fi

\M757. When there is a subscript without a superscript, the top of the
subscript
should not exceed the baseline plus four-fifths of the x-height.

\Y\P$\4\X757:Construct a subscript box \|x when there is no superscript\X\S$\6
\&{begin} \37$\|x\K\\{clean\_box}(\\{subscr}(\|q),\39\\{sub\_style}(\\{cur%
\_style}))$;\5
$\\{width}(\|x)\K\\{width}(\|x)+\\{script\_space}$;\6
\&{if} $\\{shift\_down}<\\{sub1}(\\{cur\_size})$ \1\&{then}\5
$\\{shift\_down}\K\\{sub1}(\\{cur\_size})$;\2\6
$\\{clr}\K\\{height}(\|x)-(\\{abs}(\\{math\_x\_height}(\\{cur\_size})\ast4)%
\mathbin{\&{div}}5)$;\6
\&{if} $\\{shift\_down}<\\{clr}$ \1\&{then}\5
$\\{shift\_down}\K\\{clr}$;\2\6
$\\{shift\_amount}(\|x)\K\\{shift\_down}$;\6
\&{end}\par
\U section~756.\fi

\M758. The bottom of a superscript should never descend below the baseline plus
one-fourth of the x-height.

\Y\P$\4\X758:Construct a superscript box \|x\X\S$\6
\&{begin} \37$\|x\K\\{clean\_box}(\\{supscr}(\|q),\39\\{sup\_style}(\\{cur%
\_style}))$;\5
$\\{width}(\|x)\K\\{width}(\|x)+\\{script\_space}$;\6
\&{if} $\\{odd}(\\{cur\_style})$ \1\&{then}\5
$\\{clr}\K\\{sup3}(\\{cur\_size})$\6
\4\&{else} \&{if} $\\{cur\_style}<\\{text\_style}$ \1\&{then}\5
$\\{clr}\K\\{sup1}(\\{cur\_size})$\6
\4\&{else} $\\{clr}\K\\{sup2}(\\{cur\_size})$;\2\2\6
\&{if} $\\{shift\_up}<\\{clr}$ \1\&{then}\5
$\\{shift\_up}\K\\{clr}$;\2\6
$\\{clr}\K\\{depth}(\|x)+(\\{abs}(\\{math\_x\_height}(\\{cur\_size}))\mathbin{%
\&{div}}4)$;\6
\&{if} $\\{shift\_up}<\\{clr}$ \1\&{then}\5
$\\{shift\_up}\K\\{clr}$;\2\6
\&{end}\par
\U section~756.\fi

\M759. When both subscript and superscript are present, the subscript must be
separated from the superscript by at least four times \\{default\_rule%
\_thickness}.
If this condition would be violated, the subscript moves down, after which
both subscript and superscript move up so that the bottom of the superscript
is at least as high as the baseline plus four-fifths of the x-height.

\Y\P$\4\X759:Construct a sub/superscript combination box \|x, with the
superscript offset by \\{delta}\X\S$\6
\&{begin} \37$\|y\K\\{clean\_box}(\\{subscr}(\|q),\39\\{sub\_style}(\\{cur%
\_style}))$;\5
$\\{width}(\|y)\K\\{width}(\|y)+\\{script\_space}$;\6
\&{if} $\\{shift\_down}<\\{sub2}(\\{cur\_size})$ \1\&{then}\5
$\\{shift\_down}\K\\{sub2}(\\{cur\_size})$;\2\6
$\\{clr}\K4\ast\\{default\_rule\_thickness}-((\\{shift\_up}-\\{depth}(\|x))-(%
\\{height}(\|y)-\\{shift\_down}))$;\6
\&{if} $\\{clr}>0$ \1\&{then}\6
\&{begin} \37$\\{shift\_down}\K\\{shift\_down}+\\{clr}$;\5
$\\{clr}\K(\\{abs}(\\{math\_x\_height}(\\{cur\_size})\ast4)\mathbin{%
\&{div}}5)-(\\{shift\_up}-\\{depth}(\|x))$;\6
\&{if} $\\{clr}>0$ \1\&{then}\6
\&{begin} \37$\\{shift\_up}\K\\{shift\_up}+\\{clr}$;\5
$\\{shift\_down}\K\\{shift\_down}-\\{clr}$;\6
\&{end};\2\6
\&{end};\2\6
$\\{shift\_amount}(\|x)\K\\{delta}$;\C{superscript is \\{delta} to the right of
the subscript}\6
$\|p\K\\{new\_kern}((\\{shift\_up}-\\{depth}(\|x))-(\\{height}(\|y)-\\{shift%
\_down}))$;\5
$\\{link}(\|x)\K\|p$;\5
$\\{link}(\|p)\K\|y$;\5
$\|x\K\\{vpack}(\|x,\39\\{natural})$;\5
$\\{shift\_amount}(\|x)\K\\{shift\_down}$;\6
\&{end}\par
\U section~756.\fi

\M760. We have now tied up all the loose ends of the first pass of \\{mlist\_to%
\_hlist}.
The second pass simply goes through and hooks everything together with the
proper glue and penalties. It also handles the \\{left\_noad} and \\{right%
\_noad} that
might be present, since \\{max\_h} and \\{max\_d} are now known. Variable \|p
points
to a node at the current end of the final hlist.

\Y\P$\4\X760:Make a second pass over the mlist, removing all noads and
inserting the proper spacing and penalties\X\S$\6
$\|p\K\\{temp\_head}$;\5
$\\{link}(\|p)\K\\{null}$;\5
$\|q\K\\{mlist}$;\5
$\\{r\_type}\K0$;\5
$\\{cur\_style}\K\\{style}$;\5
\X703:Set up the values of \\{cur\_size} and \\{cur\_mu}, based on \\{cur%
\_style}\X;\6
\&{while} $\|q\I\\{null}$ \1\&{do}\6
\&{begin} \37\X761:If node \|q is a style node, change the style and \&{goto} %
\\{delete\_q}; otherwise if it is not a noad, put it into the hlist, advance %
\|q, and \&{goto} \\{done}; otherwise set \|s to the size of noad \|q, set \|t
to the associated type ($\\{ord\_noad}\to\\{inner\_noad}$), and set \\{pen} to
the associated penalty\X;\6
\X766:Append inter-element spacing based on \\{r\_type} and \|t\X;\6
\X767:Append any \\{new\_hlist} entries for \|q, and any appropriate penalties%
\X;\6
$\\{r\_type}\K\|t$;\6
\4\\{delete\_q}: \37$\|r\K\|q$;\5
$\|q\K\\{link}(\|q)$;\5
$\\{free\_node}(\|r,\39\|s)$;\6
\4\\{done}: \37\&{end}\2\par
\U section~726.\fi

\M761. Just before doing the big   \&{case}  switch in the second pass, the
program
sets up default values so that most of the branches are short.

\Y\P$\4\X761:If node \|q is a style node, change the style and \&{goto} %
\\{delete\_q}; otherwise if it is not a noad, put it into the hlist, advance %
\|q, and \&{goto} \\{done}; otherwise set \|s to the size of noad \|q, set \|t
to the associated type ($\\{ord\_noad}\to\\{inner\_noad}$), and set \\{pen} to
the associated penalty\X\S$\6
$\|t\K\\{ord\_noad}$;\5
$\|s\K\\{noad\_size}$;\5
$\\{pen}\K\\{inf\_penalty}$;\6
\&{case} $\\{type}(\|q)$ \1\&{of}\6
\4$\\{op\_noad},\39\\{open\_noad},\39\\{close\_noad},\39\\{punct\_noad},\39%
\\{inner\_noad}$: \37$\|t\K\\{type}(\|q)$;\6
\4\\{bin\_noad}: \37\&{begin} \37$\|t\K\\{bin\_noad}$;\5
$\\{pen}\K\\{bin\_op\_penalty}$;\6
\&{end};\6
\4\\{rel\_noad}: \37\&{begin} \37$\|t\K\\{rel\_noad}$;\5
$\\{pen}\K\\{rel\_penalty}$;\6
\&{end};\6
\4$\\{ord\_noad},\39\\{vcenter\_noad},\39\\{over\_noad},\39\\{under\_noad}$: %
\37\\{do\_nothing};\6
\4\\{radical\_noad}: \37$\|s\K\\{radical\_noad\_size}$;\6
\4\\{accent\_noad}: \37$\|s\K\\{accent\_noad\_size}$;\6
\4\\{fraction\_noad}: \37\&{begin} \37$\|t\K\\{inner\_noad}$;\5
$\|s\K\\{fraction\_noad\_size}$;\6
\&{end};\6
\4$\\{left\_noad},\39\\{right\_noad}$: \37$\|t\K\\{make\_left\_right}(\|q,\39%
\\{style},\39\\{max\_d},\39\\{max\_h})$;\6
\4\\{style\_node}: \37\X763:Change the current style and \&{goto} \\{delete\_q}%
\X;\6
\4$\\{whatsit\_node},\39\\{penalty\_node},\39\\{rule\_node},\39\\{disc\_node},%
\39\\{adjust\_node},\39\\{ins\_node},\39\\{mark\_node},\39\\{glue\_node},\39%
\\{kern\_node}$: \37\hbox{}\6
\&{begin} \37$\\{link}(\|p)\K\|q$;\5
$\|p\K\|q$;\5
$\|q\K\\{link}(\|q)$;\5
$\\{link}(\|p)\K\\{null}$;\5
\&{goto} \37\\{done};\6
\&{end};\6
\4\&{othercases} \37$\\{confusion}(\.{"mlist3"})$\2\6
\&{endcases}\par
\U section~760.\fi

\M762. The \\{make\_left\_right} function constructs a left or right delimiter
of
the required size and returns the value \\{open\_noad} or \\{close\_noad}. The
\\{right\_noad} and \\{left\_noad} will both be based on the original %
\\{style},
so they will have consistent sizes.

We use the fact that $\\{right\_noad}-\\{left\_noad}=\\{close\_noad}-\\{open%
\_noad}$.

\Y\P$\4\X734:Declare math construction procedures\X\mathrel{+}\S$\6
\4\&{function}\1\  \37$\\{make\_left\_right}(\|q:\\{pointer};\,\35\\{style}:%
\\{small\_number};\,\35\\{max\_d},\39\\{max\_h}:\\{scaled})$: \37\\{small%
\_number};\6
\4\&{var} \37$\\{delta},\39\\{delta1},\39\\{delta2}$: \37\\{scaled};%
\C{dimensions used in the calculation}\2\6
\&{begin} \37\&{if} $\\{style}<\\{script\_style}$ \1\&{then}\5
$\\{cur\_size}\K\\{text\_size}$\6
\4\&{else} $\\{cur\_size}\K16\ast((\\{style}-\\{text\_style})\mathbin{%
\&{div}}2)$;\2\6
$\\{delta2}\K\\{max\_d}+\\{axis\_height}(\\{cur\_size})$;\5
$\\{delta1}\K\\{max\_h}+\\{max\_d}-\\{delta2}$;\6
\&{if} $\\{delta2}>\\{delta1}$ \1\&{then}\5
$\\{delta1}\K\\{delta2}$;\C{\\{delta1} is max distance from axis}\2\6
$\\{delta}\K(\\{delta1}\mathbin{\&{div}}500)\ast\\{delimiter\_factor}$;\5
$\\{delta2}\K\\{delta1}+\\{delta1}-\\{delimiter\_shortfall}$;\6
\&{if} $\\{delta}<\\{delta2}$ \1\&{then}\5
$\\{delta}\K\\{delta2}$;\2\6
$\\{new\_hlist}(\|q)\K\\{var\_delimiter}(\\{delimiter}(\|q),\39\\{cur\_size},%
\39\\{delta})$;\5
$\\{make\_left\_right}\K\\{type}(\|q)-(\\{left\_noad}-\\{open\_noad})$;\C{%
\\{open\_noad} or \\{close\_noad}}\6
\&{end};\par
\fi

\M763. \P$\X763:Change the current style and \&{goto} \\{delete\_q}\X\S$\6
\&{begin} \37$\\{cur\_style}\K\\{subtype}(\|q)$;\5
$\|s\K\\{style\_node\_size}$;\5
\X703:Set up the values of \\{cur\_size} and \\{cur\_mu}, based on \\{cur%
\_style}\X;\6
\&{goto} \37\\{delete\_q};\6
\&{end}\par
\U section~761.\fi

\M764. The inter-element spacing in math formulas depends on a $8\times8$ table
that
\TeX\ preloads as a 64-digit string. The elements of this string have the
following significance:
$$\vbox{\halign{#\hfil\cr
\.0 means no space;\cr
\.1 means a conditional thin space (\.{\\nonscript\\mskip\\thinmuskip});\cr
\.2 means a thin space (\.{\\mskip\\thinmuskip});\cr
\.3 means a conditional medium space
(\.{\\nonscript\\mskip\\medmuskip});\cr
\.4 means a conditional thick space
(\.{\\nonscript\\mskip\\thickmuskip});\cr
\.* means an impossible case.\cr}}$$
This is all pretty cryptic, but {\sl The \TeX book\/} explains what is
supposed to happen, and the string makes it happen.

A global variable \\{magic\_offset} is computed so that if \|a and \|b are
in the range $\\{ord\_noad}\to\\{inner\_noad}$, then $\\{str\_pool}[\|a\ast8+%
\|b+\\{magic\_offset}]$
is the digit for spacing between noad types \|a and \|b.

If \PASCAL\ had provided a good way to preload constant arrays, this part of
the program would not have been so strange.

\Y\P\D \37$\\{math\_spacing}=$\6
\hbox{\hskip-35pt}%
\.{"0234000122*4000133**3**344*0400400*000000234000111*1111112341011"}\hbox{$ %
\hskip-35pt$}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{magic\_offset}: \37\\{integer};\C{used to find inter-element spacing}\par
\fi

\M765. \P$\X765:Compute the magic offset\X\S$\6
$\\{magic\_offset}\K\\{str\_start}[\\{math\_spacing}]-9\ast\\{ord\_noad}$\par
\U section~1337.\fi

\M766. \P$\X766:Append inter-element spacing based on \\{r\_type} and \|t\X\S$\6
\&{if} $\\{r\_type}>0$ \1\&{then}\C{not the first noad}\6
\&{begin} \37\&{case} $\\{str\_pool}[\\{r\_type}\ast8+\|t+\\{magic\_offset}]$ %
\1\&{of}\6
\4\.{"0"}: \37$\|x\K0$;\6
\4\.{"1"}: \37\&{if} $\\{cur\_style}<\\{script\_style}$ \1\&{then}\5
$\|x\K\\{thin\_mu\_skip\_code}$\ \&{else} $\|x\K0$;\2\6
\4\.{"2"}: \37$\|x\K\\{thin\_mu\_skip\_code}$;\6
\4\.{"3"}: \37\&{if} $\\{cur\_style}<\\{script\_style}$ \1\&{then}\5
$\|x\K\\{med\_mu\_skip\_code}$\ \&{else} $\|x\K0$;\2\6
\4\.{"4"}: \37\&{if} $\\{cur\_style}<\\{script\_style}$ \1\&{then}\5
$\|x\K\\{thick\_mu\_skip\_code}$\ \&{else} $\|x\K0$;\2\6
\4\&{othercases} \37$\\{confusion}(\.{"mlist4"})$\2\6
\&{endcases};\6
\&{if} $\|x\I0$ \1\&{then}\6
\&{begin} \37$\|y\K\\{math\_glue}(\\{glue\_par}(\|x),\39\\{cur\_mu})$;\5
$\|z\K\\{new\_glue}(\|y)$;\5
$\\{glue\_ref\_count}(\|y)\K\\{null}$;\5
$\\{link}(\|p)\K\|z$;\5
$\|p\K\|z$;\6
$\\{subtype}(\|z)\K\|x+1$;\C{store a symbolic subtype}\6
\&{end};\2\6
\&{end}\2\par
\U section~760.\fi

\M767. We insert a penalty node after the hlist entries of noad \|q if \\{pen}
is not an ``infinite'' penalty, and if the node immediately following \|q
is not a penalty node or a \\{rel\_noad} or absent entirely.

\Y\P$\4\X767:Append any \\{new\_hlist} entries for \|q, and any appropriate
penalties\X\S$\6
\&{if} $\\{new\_hlist}(\|q)\I\\{null}$ \1\&{then}\6
\&{begin} \37$\\{link}(\|p)\K\\{new\_hlist}(\|q)$;\6
\1\&{repeat} \37$\|p\K\\{link}(\|p)$;\6
\4\&{until}\5
$\\{link}(\|p)=\\{null}$;\2\6
\&{end};\2\6
\&{if} $\\{penalties}$ \1\&{then}\6
\&{if} $\\{link}(\|q)\I\\{null}$ \1\&{then}\6
\&{if} $\\{pen}<\\{inf\_penalty}$ \1\&{then}\6
\&{begin} \37$\\{r\_type}\K\\{type}(\\{link}(\|q))$;\6
\&{if} $\\{r\_type}\I\\{penalty\_node}$ \1\&{then}\6
\&{if} $\\{r\_type}\I\\{rel\_noad}$ \1\&{then}\6
\&{begin} \37$\|z\K\\{new\_penalty}(\\{pen})$;\5
$\\{link}(\|p)\K\|z$;\5
$\|p\K\|z$;\6
\&{end};\2\2\6
\&{end}\2\2\2\par
\U section~760.\fi

\N768.  \[37] Alignment.
It's sort of a miracle whenever \.{\\halign} and \.{\\valign} work, because
they cut across so many of the control structures of \TeX. Therefore the
present page is probably not the best place for a beginner to start reading
this program; it is better to master everything else first.

Let us focus our thoughts on an example of what the input might be, in order
to get some idea about how the alignment miracle happens. The example doesn't
do anything useful, but it is sufficiently general to indicate all of the
special cases that must be dealt with; please do not be disturbed by its
apparent complexity and meaninglessness.
$$\vbox{\halign{\.{#}\hfil\cr
{}\\tabskip 2pt plus 3pt\cr
{}\\halign to 300pt\{u1\#v1\&\cr
\hskip 50pt\\tabskip 1pt plus 1fil u2\#v2\&\cr
\hskip 50pt u3\#v3\\cr\cr
\hskip 25pt a1\&\\omit a2\&\\vrule\\cr\cr
\hskip 25pt \\noalign\{\\vskip 3pt\}\cr
\hskip 25pt b1\\span b2\\cr\cr
\hskip 25pt \\omit\&c2\\span\\omit\\cr\}\cr}}$$
Here's what happens:

\yskip
(0) When `\.{\\halign to 300pt\{}' is scanned, the \\{scan\_spec} routine
places the 300pt dimension onto the \\{save\_stack}, and an \\{align\_group}
code is placed above it. This will make it possible to complete the alignment
when the matching `\.\}' is found.

(1) The preamble is scanned next. Macros in the preamble are not expanded,
except as part of a tabskip specification. For example, if \.{u2} had been
a macro in the preamble above, it would have been expanded, since \TeX\
must look for `\.{minus...}' as part of the tabskip glue. A ``preamble list''
is constructed based on the user's preamble; in our case it contains the
following seven items:
$$\vbox{\halign{\.{#}\hfil\qquad&(#)\hfil\cr
{}\\glue 2pt plus 3pt&the tabskip preceding column 1\cr
{}\\alignrecord, width $-\infty$&preamble info for column 1\cr
{}\\glue 2pt plus 3pt&the tabskip between columns 1 and 2\cr
{}\\alignrecord, width $-\infty$&preamble info for column 2\cr
{}\\glue 1pt plus 1fil&the tabskip between columns 2 and 3\cr
{}\\alignrecord, width $-\infty$&preamble info for column 3\cr
{}\\glue 1pt plus 1fil&the tabskip following column 3\cr}}$$
These ``alignrecord'' entries have the same size as an \\{unset\_node},
since they will later be converted into such nodes. However, at the
moment they have no \\{type} or \\{subtype} fields; they have \\{info} fields
instead, and these \\{info} fields are initially set to the value \\{end%
\_span},
for reasons explained below. Furthermore, the alignrecord nodes have no
\\{height} or \\{depth} fields; these are renamed \\{u\_part} and \\{v\_part},
and they point to token lists for the templates of the alignment.
For example, the \\{u\_part} field in the first alignrecord points to the
token list `\.{u1}', i.e., the template preceding the `\.\#' for column~1.

(2) \TeX\ now looks at what follows the \.{\\cr} that ended the preamble.
It is not `\.{\\noalign}' or `\.{\\omit}', so this input is put back to
be read again, and the template `\.{u1}' is fed to the scanner. Just
before reading `\.{u1}', \TeX\ goes into restricted horizontal mode.
Just after reading `\.{u1}', \TeX\ will see `\.{a1}', and then (when the
{\.\&} is sensed) \TeX\ will see `\.{v1}'. Then \TeX\ scans an \\{endv}
token, indicating the end of a column. At this point an \\{unset\_node} is
created, containing the contents of the current hlist (i.e., `\.{u1a1v1}').
The natural width of this unset node replaces the \\{width} field of the
alignrecord for column~1; in general, the alignrecords will record the
maximum natural width that has occurred so far in a given column.

(3) Since `\.{\\omit}' follows the `\.\&', the templates for column~2
are now bypassed. Again \TeX\ goes into restricted horizontal mode and
makes an \\{unset\_node} from the resulting hlist; but this time the
hlist contains simply `\.{a2}'. The natural width of the new unset box
is remembered in the \\{width} field of the alignrecord for column~2.

(4) A third \\{unset\_node} is created for column 3, using essentially the
mechanism that worked for column~1; this unset box contains `\.{u3\\vrule
v3}'. The vertical rule in this case has running dimensions that will later
extend to the height and depth of the whole first row, since each \\{unset%
\_node}
in a row will eventually inherit the height and depth of its enclosing box.

(5) The first row has now ended; it is made into a single unset box
comprising the following seven items:
$$\vbox{\halign{\hbox to 325pt{\qquad\.{#}\hfil}\cr
{}\\glue 2pt plus 3pt\cr
{}\\unsetbox for 1 column: u1a1v1\cr
{}\\glue 2pt plus 3pt\cr
{}\\unsetbox for 1 column: a2\cr
{}\\glue 1pt plus 1fil\cr
{}\\unsetbox for 1 column: u3\vrule v3\cr
{}\\glue 1pt plus 1fil\cr}}$$
The width of this unset row is unimportant, but it has the correct height
and depth, so the correct baselineskip glue will be computed as the row
is inserted into a vertical list.

(6) Since `\.{\\noalign}' follows the current \.{\\cr}, \TeX\ appends
additional material (in this case \.{\\vskip 3pt}) to the vertical list.
While processing this material, \TeX\ will be in internal vertical
mode, and \\{no\_align\_group} will be on \\{save\_stack}.

(7) The next row produces an unset box that looks like this:
$$\vbox{\halign{\hbox to 325pt{\qquad\.{#}\hfil}\cr
{}\\glue 2pt plus 3pt\cr
{}\\unsetbox for 2 columns: u1b1v1u2b2v2\cr
{}\\glue 1pt plus 1fil\cr
{}\\unsetbox for 1 column: {\rm(empty)}\cr
{}\\glue 1pt plus 1fil\cr}}$$
The natural width of the unset box that spans columns 1~and~2 is stored
in a ``span node,'' which we will explain later; the \\{info} field of the
alignrecord for column~1 now points to the new span node, and the \\{info}
of the span node points to \\{end\_span}.

(8) The final row produces the unset box
$$\vbox{\halign{\hbox to 325pt{\qquad\.{#}\hfil}\cr
{}\\glue 2pt plus 3pt\cr
{}\\unsetbox for 1 column: {\rm(empty)}\cr
{}\\glue 2pt plus 3pt\cr
{}\\unsetbox for 2 columns: u2c2v2\cr
{}\\glue 1pt plus 1fil\cr}}$$
A new span node is attached to the alignrecord for column 2.

(9) The last step is to compute the true column widths and to change all the
unset boxes to hboxes, appending the whole works to the vertical list that
encloses the \.{\\halign}. The rules for deciding on the final widths of
each unset column box will be explained below.

\yskip\noindent
Note that as \.{\\halign} is being processed, we fearlessly give up control
to the rest of \TeX. At critical junctures, an alignment routine is
called upon to step in and do some little action, but most of the time
these routines just lurk in the background. It's something like
post-hypnotic suggestion.

\fi

\M769. We have mentioned that alignrecords contain no \\{height} or \\{depth}
fields.
Their \\{glue\_sign} and \\{glue\_order} are pre-empted as well, since it
is necessary to store information about what to do when a template ends.
This information is called the \\{extra\_info} field.

\Y\P\D \37$\\{u\_part}(\#)\S\\{mem}[\#+\\{height\_offset}].\\{int}$\C{pointer
to \<u_j> token list}\par
\P\D \37$\\{v\_part}(\#)\S\\{mem}[\#+\\{depth\_offset}].\\{int}$\C{pointer to %
\<v_j> token list}\par
\P\D \37$\\{extra\_info}(\#)\S\\{info}(\#+\\{list\_offset})$\C{info to remember
during template}\par
\fi

\M770. Alignments can occur within alignments, so a small stack is used to
access
the alignrecord information. At each level we have a \\{preamble} pointer,
indicating the beginning of the preamble list; a \\{cur\_align} pointer,
indicating the current position in the preamble list; a \\{cur\_span} pointer,
indicating the value of \\{cur\_align} at the beginning of a sequence of
spanned columns; a \\{cur\_loop} pointer, indicating the tabskip glue before
an alignrecord that should be copied next if the current list is extended;
and the \\{align\_state} variable, which indicates the nesting of braces so
that \.{\\cr} and \.{\\span} and tab marks are properly intercepted.
There also are pointers \\{cur\_head} and \\{cur\_tail} to the head and tail
of a list of adjustments being moved out from horizontal mode to
vertical mode.

The current values of these seven quantities appear in global variables;
when they have to be pushed down, they are stored in 5-word nodes, and
\\{align\_ptr} points to the topmost such node.

\Y\P\D \37$\\{preamble}\S\\{link}(\\{align\_head})$\C{the current preamble
list}\par
\P\D \37$\\{align\_stack\_node\_size}=5$\C{number of \\{mem} words to save
alignment states}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{cur\_align}: \37\\{pointer};\C{current position in preamble list}\6
\4\\{cur\_span}: \37\\{pointer};\C{start of currently spanned columns in
preamble list}\6
\4\\{cur\_loop}: \37\\{pointer};\C{place to copy when extending a periodic
preamble}\6
\4\\{align\_ptr}: \37\\{pointer};\C{most recently pushed-down alignment stack
node}\6
\4$\\{cur\_head},\39\\{cur\_tail}$: \37\\{pointer};\C{adjustment list pointers}%
\par
\fi

\M771. The \\{align\_state} and \\{preamble} variables are initialized
elsewhere.

\Y\P$\4\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{align\_ptr}\K\\{null}$;\5
$\\{cur\_align}\K\\{null}$;\5
$\\{cur\_span}\K\\{null}$;\5
$\\{cur\_loop}\K\\{null}$;\5
$\\{cur\_head}\K\\{null}$;\5
$\\{cur\_tail}\K\\{null}$;\par
\fi

\M772. Alignment stack maintenance is handled by a pair of trivial routines
called \\{push\_alignment} and \\{pop\_alignment}.

\Y\P\4\&{procedure}\1\  \37\\{push\_alignment};\6
\4\&{var} \37\|p: \37\\{pointer};\C{the new alignment stack node}\2\6
\&{begin} \37$\|p\K\\{get\_node}(\\{align\_stack\_node\_size})$;\5
$\\{link}(\|p)\K\\{align\_ptr}$;\5
$\\{info}(\|p)\K\\{cur\_align}$;\5
$\\{llink}(\|p)\K\\{preamble}$;\5
$\\{rlink}(\|p)\K\\{cur\_span}$;\5
$\\{mem}[\|p+2].\\{int}\K\\{cur\_loop}$;\5
$\\{mem}[\|p+3].\\{int}\K\\{align\_state}$;\5
$\\{info}(\|p+4)\K\\{cur\_head}$;\5
$\\{link}(\|p+4)\K\\{cur\_tail}$;\5
$\\{align\_ptr}\K\|p$;\5
$\\{cur\_head}\K\\{get\_avail}$;\6
\&{end};\7
\4\&{procedure}\1\  \37\\{pop\_alignment};\6
\4\&{var} \37\|p: \37\\{pointer};\C{the top alignment stack node}\2\6
\&{begin} \37$\\{free\_avail}(\\{cur\_head})$;\5
$\|p\K\\{align\_ptr}$;\5
$\\{cur\_tail}\K\\{link}(\|p+4)$;\5
$\\{cur\_head}\K\\{info}(\|p+4)$;\5
$\\{align\_state}\K\\{mem}[\|p+3].\\{int}$;\5
$\\{cur\_loop}\K\\{mem}[\|p+2].\\{int}$;\5
$\\{cur\_span}\K\\{rlink}(\|p)$;\5
$\\{preamble}\K\\{llink}(\|p)$;\5
$\\{cur\_align}\K\\{info}(\|p)$;\5
$\\{align\_ptr}\K\\{link}(\|p)$;\5
$\\{free\_node}(\|p,\39\\{align\_stack\_node\_size})$;\6
\&{end};\par
\fi

\M773. \TeX\ has eight procedures that govern alignments: \\{init\_align} and
\\{fin\_align} are used at the very beginning and the very end; \\{init\_row}
and
\\{fin\_row} are used at the beginning and end of individual rows; \\{init%
\_span}
is used at the beginning of a sequence of spanned columns (possibly involving
only one column); \\{init\_col} and \\{fin\_col} are used at the beginning and
end of individual columns; and \\{align\_peek} is used after \.{\\cr} to see
whether the next item is \.{\\noalign}.

We shall consider these routines in the order they are first used during
the course of a complete \.{\\halign}, namely \\{init\_align}, \\{align\_peek},
\\{init\_row}, \\{init\_span}, \\{init\_col}, \\{fin\_col}, \\{fin\_row}, %
\\{fin\_align}.

\fi

\M774. When \.{\\halign} or \.{\\valign} has been scanned in an appropriate
mode, \TeX\ calls \\{init\_align}, whose task is to get everything off to a
good start. This mostly involves scanning the preamble and putting its
information into the preamble list.

\Y\P\hbox{\4}\X782:Declare the procedure called \\{get\_preamble\_token}\X%
\hbox{}\6
\4\&{procedure}\1\  \37\\{align\_peek};\5
\\{forward};\5
\hbox{\2}\6
\4\&{procedure}\1\  \37\\{normal\_paragraph};\5
\\{forward};\5
\hbox{\2}\6
\4\&{procedure}\1\  \37\\{init\_align};\6
\4\&{label} \37$\\{done},\39\\{done1},\39\\{done2},\39\\{continue}$;\6
\4\&{var} \37\\{save\_cs\_ptr}: \37\\{pointer};\C{\\{warning\_index} value for
error messages}\6
\|p: \37\\{pointer};\C{for short-term temporary use}\2\6
\&{begin} \37$\\{save\_cs\_ptr}\K\\{cur\_cs}$;\C{\.{\\halign} or \.{\\valign},
usually}\6
\\{push\_alignment};\5
$\\{align\_state}\K-1000000$;\C{enter a new alignment level}\6
\X776:Check for improper alignment in displayed math\X;\6
\\{push\_nest};\C{enter a new semantic level}\6
\X775:Change current mode to $-\\{vmode}$ for \.{\\halign}, $-\\{hmode}$ for %
\.{\\valign}\X;\6
\\{scan\_spec};\5
$\\{new\_save\_level}(\\{align\_group})$;\6
\X777:Scan the preamble and record it in the \\{preamble} list\X;\6
$\\{new\_save\_level}(\\{align\_group})$;\6
\&{if} $\\{every\_cr}\I\\{null}$ \1\&{then}\5
$\\{begin\_token\_list}(\\{every\_cr},\39\\{every\_cr\_text})$;\2\6
\\{align\_peek};\C{look for \.{\\noalign} or \.{\\omit}}\6
\&{end};\par
\fi

\M775. In vertical modes, \\{prev\_depth} already has the correct value. But
if we are in \\{mmode} (displayed formula mode), we reach out to the
enclosing vertical mode for the \\{prev\_depth} value that produces the
correct baseline calculations.

\Y\P$\4\X775:Change current mode to $-\\{vmode}$ for \.{\\halign}, $-\\{hmode}$
for \.{\\valign}\X\S$\6
\&{if} $\\{mode}=\\{mmode}$ \1\&{then}\6
\&{begin} \37$\\{mode}\K-\\{vmode}$;\5
$\\{prev\_depth}\K\\{nest}[\\{nest\_ptr}-2].\\{aux\_field}$;\6
\&{end}\6
\4\&{else} \&{if} $\\{mode}>0$ \1\&{then}\5
$\\{negate}(\\{mode})$\2\2\par
\U section~774.\fi

\M776. When \.{\\halign} is used as a displayed formula, there should be
no other pieces of mlists present.

\Y\P$\4\X776:Check for improper alignment in displayed math\X\S$\6
\&{if} $(\\{mode}=\\{mmode})\W((\\{tail}\I\\{head})\V(\\{incompleat\_noad}\I%
\\{null}))$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Improper\ "})$;\5
$\\{print\_esc}(\.{"halign"})$;\5
$\\{print}(\.{"\ inside\ \$\$\'s"})$;\5
$\\{help3}(\.{"Displays\ can\ use\ special\ alignments\ (like\ \\eqalignno)"})$%
\6
$(\.{"only\ if\ nothing\ but\ the\ alignment\ itself\ is\ between\ \$\$\'s."})$%
\6
$(\.{"So\ I\'ve\ deleted\ the\ formulas\ that\ preceded\ this\ alignment."})$;\5
\\{error};\5
\\{flush\_math};\6
\&{end}\2\par
\U section~774.\fi

\M777. \P$\X777:Scan the preamble and record it in the \\{preamble} list\X\S$\6
$\\{preamble}\K\\{null}$;\5
$\\{cur\_align}\K\\{align\_head}$;\5
$\\{cur\_loop}\K\\{null}$;\5
$\\{scanner\_status}\K\\{aligning}$;\5
$\\{warning\_index}\K\\{save\_cs\_ptr}$;\5
$\\{align\_state}\K-1000000$;\C{at this point, $\\{cur\_cmd}=\\{left\_brace}$}\6
\~ \1\&{loop}\ \&{begin} \37\X778:Append the current tabskip glue to the
preamble list\X;\6
\&{if} $\\{cur\_cmd}=\\{car\_ret}$ \1\&{then}\5
\&{goto} \37\\{done};\C{\.{\\cr} ends the preamble}\2\6
\X779:Scan preamble text until \\{cur\_cmd} is \\{tab\_mark} or \\{car\_ret},
looking for changes in the tabskip glue; append an alignrecord to the preamble
list\X;\6
\&{end};\2\6
\4\\{done}: \37$\\{scanner\_status}\K\\{normal}$\par
\U section~774.\fi

\M778. \P$\X778:Append the current tabskip glue to the preamble list\X\S$\6
$\\{link}(\\{cur\_align})\K\\{new\_param\_glue}(\\{tab\_skip\_code})$;\5
$\\{cur\_align}\K\\{link}(\\{cur\_align})$\par
\U section~777.\fi

\M779. \P$\X779:Scan preamble text until \\{cur\_cmd} is \\{tab\_mark} or %
\\{car\_ret}, looking for changes in the tabskip glue; append an alignrecord to
the preamble list\X\S$\6
\X783:Scan the template \<u_j>, putting the resulting token list in \\{hold%
\_head}\X;\6
$\\{link}(\\{cur\_align})\K\\{new\_null\_box}$;\5
$\\{cur\_align}\K\\{link}(\\{cur\_align})$;\C{a new alignrecord}\6
$\\{info}(\\{cur\_align})\K\\{end\_span}$;\5
$\\{width}(\\{cur\_align})\K\\{null\_flag}$;\5
$\\{u\_part}(\\{cur\_align})\K\\{link}(\\{hold\_head})$;\5
\X784:Scan the template \<v_j>, putting the resulting token list in \\{hold%
\_head}\X;\6
$\\{v\_part}(\\{cur\_align})\K\\{link}(\\{hold\_head})$\par
\U section~777.\fi

\M780. We enter `\.{\\span}' into \\{eqtb} with \\{tab\_mark} as its command
code,
and with \\{span\_code} as the command modifier. This makes \TeX\ interpret it
essentially the same as an alignment delimiter like `\.\&', yet it is
recognizably different when we need to distinguish it from a normal delimiter.
It also turns out to be useful to give a special \\{cr\_code} to `\.{\\cr}',
and an even larger \\{cr\_cr\_code} to `\.{\\crcr}'.

The end of a template is represented by two ``frozen'' control sequences
called \.{\\endtemplate}. The first has the command code \\{end\_template},
which
is $>\\{outer\_call}$, so it will not easily disappear in the presence of
errors.
The \\{get\_x\_token} routine converts the first into the second, which has %
\\{endv}
as its command code.

\Y\P\D \37$\\{span\_code}=128$\C{distinct from any character}\par
\P\D \37$\\{cr\_code}=129$\C{distinct from \\{span\_code} and from any
character}\par
\P\D \37$\\{cr\_cr\_code}=\\{cr\_code}+1$\C{this distinguishes \.{\\crcr} from %
\.{\\cr}}\par
\P\D \37$\\{end\_template\_token}\S\\{cs\_token\_flag}+\\{frozen\_end%
\_template}$\par
\Y\P$\4\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}\S$\6
$\\{primitive}(\.{"span"},\39\\{tab\_mark},\39\\{span\_code})$;\6
$\\{primitive}(\.{"cr"},\39\\{car\_ret},\39\\{cr\_code})$;\5
$\\{text}(\\{frozen\_cr})\K\.{"cr"}$;\5
$\\{eqtb}[\\{frozen\_cr}]\K\\{eqtb}[\\{cur\_val}]$;\6
$\\{primitive}(\.{"crcr"},\39\\{car\_ret},\39\\{cr\_cr\_code})$;\5
$\\{text}(\\{frozen\_end\_template})\K\.{"endtemplate"}$;\5
$\\{text}(\\{frozen\_endv})\K\.{"endtemplate"}$;\5
$\\{eq\_type}(\\{frozen\_endv})\K\\{endv}$;\5
$\\{equiv}(\\{frozen\_endv})\K\\{null\_list}$;\5
$\\{eq\_level}(\\{frozen\_endv})\K\\{level\_one}$;\6
$\\{eqtb}[\\{frozen\_end\_template}]\K\\{eqtb}[\\{frozen\_endv}]$;\5
$\\{eq\_type}(\\{frozen\_end\_template})\K\\{end\_template}$;\par
\fi

\M781. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{tab\_mark}: \37\&{if} $\\{chr\_code}=\\{span\_code}$ \1\&{then}\5
$\\{print\_esc}(\.{"span"})$\6
\4\&{else} $\\{chr\_cmd}(\.{"alignment\ tab\ character\ "})$;\2\6
\4\\{car\_ret}: \37\&{if} $\\{chr\_code}=\\{cr\_code}$ \1\&{then}\5
$\\{print\_esc}(\.{"cr"})$\6
\4\&{else} $\\{print\_esc}(\.{"crcr"})$;\2\par
\fi

\M782. The preamble is copied directly, except that \.{\\tabskip} causes a
change
to the tabskip glue, thereby possibly expanding macros that immediately
follow it. An appearance of \.{\\span} also causes such an expansion.

Note that if the preamble contains `\.{\\global\\tabskip}', the `\.{\\global}'
token survives in the preamble and the `\.{\\tabskip}' defines new
tabskip glue (locally).

\Y\P$\4\X782:Declare the procedure called \\{get\_preamble\_token}\X\S$\6
\4\&{procedure}\1\  \37\\{get\_preamble\_token};\6
\4\&{label} \37\\{restart};\2\6
\&{begin} \37\\{restart}: \37\\{get\_token};\6
\&{while} $(\\{cur\_chr}=\\{span\_code})\W(\\{cur\_cmd}=\\{tab\_mark})$ \1%
\&{do}\6
\&{begin} \37\\{get\_token};\C{this token will be expanded once}\6
\&{if} $\\{cur\_cmd}>\\{max\_command}$ \1\&{then}\6
\&{begin} \37\\{expand};\5
\\{get\_token};\6
\&{end};\2\6
\&{end};\2\6
\&{if} $(\\{cur\_cmd}=\\{assign\_glue})\W(\\{cur\_chr}=\\{glue\_base}+\\{tab%
\_skip\_code})$ \1\&{then}\6
\&{begin} \37\\{scan\_optional\_equals};\5
$\\{scan\_glue}(\\{glue\_val})$;\6
\&{if} $\\{global\_defs}>0$ \1\&{then}\5
$\\{geq\_define}(\\{glue\_base}+\\{tab\_skip\_code},\39\\{glue\_ref},\39\\{cur%
\_val})$\6
\4\&{else} $\\{eq\_define}(\\{glue\_base}+\\{tab\_skip\_code},\39\\{glue\_ref},%
\39\\{cur\_val})$;\2\6
\&{goto} \37\\{restart};\6
\&{end};\2\6
\&{end};\par
\U section~774.\fi

\M783. Spaces are eliminated from the beginning of a template.

\Y\P$\4\X783:Scan the template \<u_j>, putting the resulting token list in %
\\{hold\_head}\X\S$\6
$\|p\K\\{hold\_head}$;\5
$\\{link}(\|p)\K\\{null}$;\6
\~ \1\&{loop}\ \&{begin} \37\\{get\_preamble\_token};\6
\&{if} $\\{cur\_cmd}=\\{mac\_param}$ \1\&{then}\5
\&{goto} \37\\{done1};\2\6
\&{if} $(\\{cur\_cmd}\L\\{car\_ret})\W(\\{cur\_cmd}\G\\{tab\_mark})\W(\\{align%
\_state}=-1000000)$ \1\&{then}\6
\&{if} $(\|p=\\{hold\_head})\W(\\{cur\_loop}=\\{null})\W(\\{cur\_cmd}=\\{tab%
\_mark})$ \1\&{then}\5
$\\{cur\_loop}\K\\{cur\_align}$\6
\4\&{else} \&{begin} \37$\\{print\_err}(\.{"Missing\ \#\ inserted\ in\
alignment\ preamble"})$;\5
$\\{help3}(\.{"There\ should\ be\ exactly\ one\ \#\ between\ \&\'s,\ when\
an"})$\6
$(\.{"\\halign\ or\ \\valign\ is\ being\ set\ up.\ In\ this\ case\ you\ had"})$%
\6
$(\.{"none,\ so\ I\'ve\ put\ one\ in;\ maybe\ that\ will\ work."})$;\5
\\{back\_error};\5
\&{goto} \37\\{done1};\6
\&{end}\2\6
\4\&{else} \&{if} $(\\{cur\_cmd}\I\\{spacer})\V(\|p\I\\{hold\_head})$ \1%
\&{then}\6
\&{begin} \37$\\{link}(\|p)\K\\{get\_avail}$;\5
$\|p\K\\{link}(\|p)$;\5
$\\{info}(\|p)\K\\{cur\_tok}$;\6
\&{end};\2\2\6
\&{end};\2\6
\4\\{done1}: \37\par
\U section~779.\fi

\M784. \P$\X784:Scan the template \<v_j>, putting the resulting token list in %
\\{hold\_head}\X\S$\6
$\|p\K\\{hold\_head}$;\5
$\\{link}(\|p)\K\\{null}$;\6
\~ \1\&{loop}\ \&{begin} \37\\{continue}: \37\\{get\_preamble\_token};\6
\&{if} $(\\{cur\_cmd}\L\\{car\_ret})\W(\\{cur\_cmd}\G\\{tab\_mark})\W(\\{align%
\_state}=-1000000)$ \1\&{then}\5
\&{goto} \37\\{done2};\2\6
\&{if} $\\{cur\_cmd}=\\{mac\_param}$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Only\ one\ \#\ is\ allowed\ per\ tab"})$;\5
$\\{help3}(\.{"There\ should\ be\ exactly\ one\ \#\ between\ \&\'s,\ when\
an"})$\6
$(\.{"\\halign\ or\ \\valign\ is\ being\ set\ up.\ In\ this\ case\ you\ had"})$%
\6
$(\.{"more\ than\ one,\ so\ I\'m\ ignoring\ all\ but\ the\ first."})$;\5
\\{error};\5
\&{goto} \37\\{continue};\6
\&{end};\2\6
$\\{link}(\|p)\K\\{get\_avail}$;\5
$\|p\K\\{link}(\|p)$;\5
$\\{info}(\|p)\K\\{cur\_tok}$;\6
\&{end};\2\6
\4\\{done2}: \37$\\{link}(\|p)\K\\{get\_avail}$;\5
$\|p\K\\{link}(\|p)$;\5
$\\{info}(\|p)\K\\{end\_template\_token}$\C{put \.{\\endtemplate} at the end}%
\par
\U section~779.\fi

\M785. The tricky part about alignments is getting the templates into the
scanner at the right time, and recovering control when a row or column
is finished.

We usually begin a row after each \.{\\cr} has been sensed, unless that
\.{\\cr} is followed by \.{\\noalign} or by the right brace that terminates
the alignment. The \\{align\_peek} routine is used to look ahead and do
the right thing; it either gets a new row started, or gets a \.{\\noalign}
started, or finishes off the alignment.

\Y\P$\4\X785:Declare the procedure called \\{align\_peek}\X\S$\6
\4\&{procedure}\1\  \37\\{align\_peek};\6
\4\&{label} \37\\{restart};\2\6
\&{begin} \37\\{restart}: \37$\\{align\_state}\K1000000$;\5
\X406:Get the next non-blank non-call token\X;\6
\&{if} $\\{cur\_cmd}=\\{no\_align}$ \1\&{then}\6
\&{begin} \37\\{scan\_left\_brace};\5
$\\{new\_save\_level}(\\{no\_align\_group})$;\6
\&{if} $\\{mode}=-\\{vmode}$ \1\&{then}\5
\\{normal\_paragraph};\2\6
\&{end}\6
\4\&{else} \&{if} $\\{cur\_cmd}=\\{right\_brace}$ \1\&{then}\5
\\{fin\_align}\6
\4\&{else} \&{if} $(\\{cur\_cmd}=\\{car\_ret})\W(\\{cur\_chr}=\\{cr\_cr%
\_code})$ \1\&{then}\5
\&{goto} \37\\{restart}\C{ignore \.{\\crcr}}\6
\4\&{else} \&{begin} \37\\{init\_row};\C{start a new row}\6
\\{init\_col};\C{start a new column and replace what we peeked at}\6
\&{end};\2\2\2\6
\&{end};\par
\U section~800.\fi

\M786. To start a row (i.e., a `row' that rhymes with `dough' but not with
`bough'),
we enter a new semantic level, copy the first tabskip glue, and change
from internal vertical mode to restricted horizontal mode or vice versa.
The \\{space\_factor} and \\{prev\_depth} are not used on this semantic level,
but we clear \\{aux} to zero just to be tidy.

\Y\P\hbox{\4}\X787:Declare the procedure called \\{init\_span}\X\hbox{}\6
\4\&{procedure}\1\  \37\\{init\_row};\2\6
\&{begin} \37\\{push\_nest};\5
$\\{mode}\K(-\\{hmode}-\\{vmode})-\\{mode}$;\5
$\\{aux}\K0$;\5
$\\{tail\_append}(\\{new\_glue}(\\{glue\_ptr}(\\{preamble})))$;\5
$\\{subtype}(\\{tail})\K\\{tab\_skip\_code}+1$;\6
$\\{cur\_align}\K\\{link}(\\{preamble})$;\5
$\\{cur\_tail}\K\\{cur\_head}$;\5
$\\{init\_span}(\\{cur\_align})$;\6
\&{end};\par
\fi

\M787. The parameter to \\{init\_span} is a pointer to the alignrecord where
the
next column or group of columns will begin. A new semantic level is
entered, so that the columns will generate a list for subsequent packaging.

\Y\P$\4\X787:Declare the procedure called \\{init\_span}\X\S$\6
\4\&{procedure}\1\  \37$\\{init\_span}(\|p:\\{pointer})$;\2\6
\&{begin} \37\\{push\_nest};\6
\&{if} $\\{mode}=-\\{hmode}$ \1\&{then}\5
$\\{space\_factor}\K1000$\6
\4\&{else} \&{begin} \37$\\{prev\_depth}\K\\{ignore\_depth}$;\5
\\{normal\_paragraph};\6
\&{end};\2\6
$\\{cur\_span}\K\|p$;\6
\&{end};\par
\U section~786.\fi

\M788. When a column begins, we assume that \\{cur\_cmd} is either \\{omit} or
else
the current token should be put back into the input until the \<u_j>
template has been scanned.  (Note that \\{cur\_cmd} might be \\{tab\_mark} or
\\{car\_ret}.)  We also assume that \\{align\_state} is approximately 1000000
at
this time.  We remain in the same mode, and start the template if it is
called for.

\Y\P\4\&{procedure}\1\  \37\\{init\_col};\2\6
\&{begin} \37$\\{extra\_info}(\\{cur\_align})\K\\{cur\_cmd}$;\6
\&{if} $\\{cur\_cmd}=\\{omit}$ \1\&{then}\5
$\\{align\_state}\K0$\6
\4\&{else} \&{begin} \37\\{back\_input};\5
$\\{begin\_token\_list}(\\{u\_part}(\\{cur\_align}),\39\\{u\_template})$;\6
\&{end};\C{now $\\{align\_state}=1000000$}\2\6
\&{end};\par
\fi

\M789. The scanner sets \\{align\_state} to zero when the \<u_j> template ends.
When
a subsequent \.{\\cr} or \.{\\span} or tab mark occurs with $\\{align%
\_state}=0$,
the scanner activates the following code, which fires up the \<v_j> template.
We need to remember the \\{cur\_chr}, which is either \\{cr\_cr\_code}, \\{cr%
\_code},
\\{span\_code}, or a character code, depending on how the column text has
ended.

This part of the program had better not be activated when the preamble
to another alignment is being scanned.

\Y\P$\4\X789:Insert the \(v)\<v_j> template and \&{goto} \\{restart}\X\S$\6
\&{begin} \37\&{if} $\\{scanner\_status}=\\{aligning}$ \1\&{then}\5
$\\{fatal\_error}(\.{"(interwoven\ alignment\ preambles\ are\ not\
allowed)"})$;\2\6
$\\{cur\_cmd}\K\\{extra\_info}(\\{cur\_align})$;\5
$\\{extra\_info}(\\{cur\_align})\K\\{cur\_chr}$;\6
\&{if} $\\{cur\_cmd}=\\{omit}$ \1\&{then}\5
$\\{begin\_token\_list}(\\{omit\_template},\39\\{v\_template})$\6
\4\&{else} $\\{begin\_token\_list}(\\{v\_part}(\\{cur\_align}),\39\\{v%
\_template})$;\2\6
$\\{align\_state}\K1000000$;\5
\&{goto} \37\\{restart};\6
\&{end}\par
\U section~342.\fi

\M790. The token list \\{omit\_template} just referred to is a constant token
list that contains \.{\\endtemplate} only.

\Y\P$\4\X790:Initialize the special list heads and constant nodes\X\S$\6
$\\{info}(\\{omit\_template})\K\\{end\_template\_token}$;\C{$\\{link}(\\{omit%
\_template})=\\{null}$}\par
\A sections~797, 820, 981, and~988.
\U section~164.\fi

\M791. When the \\{endv} command at the end of a \<v_j> template comes through
the
scanner, things really start to happen; and it is the \\{fin\_col} routine
that makes them happen. This routine returns \\{true} if a row as well as a
column has been finished.

\Y\P\4\&{function}\1\  \37\\{fin\_col}: \37\\{boolean};\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37\|p: \37\\{pointer};\C{the alignrecord after the current one}\6
$\|q,\39\|r$: \37\\{pointer};\C{temporary pointers for list manipulation}\6
\|s: \37\\{pointer};\C{a new span node}\6
\|u: \37\\{pointer};\C{a new unset box}\6
\|w: \37\\{scaled};\C{natural width}\6
\|o: \37\\{glue\_ord};\C{order of infinity}\6
\|n: \37\\{halfword};\C{span counter}\2\6
\&{begin} \37$\|q\K\\{link}(\\{cur\_align})$;\6
\&{if} $(\\{cur\_align}=\\{null})\V(\|q=\\{null})$ \1\&{then}\5
$\\{confusion}(\.{"endv"})$;\2\6
$\|p\K\\{link}(\|q)$;\5
\X792:If the preamble list has been traversed, check that the row has ended\X;\6
\&{if} $\\{extra\_info}(\\{cur\_align})\I\\{span\_code}$ \1\&{then}\6
\&{begin} \37\\{unsave};\5
$\\{new\_save\_level}(\\{align\_group})$;\6
\X796:Package an unset box for the current column and record its width\X;\6
\X795:Copy the tabskip glue between columns\X;\6
\&{if} $\\{extra\_info}(\\{cur\_align})\G\\{cr\_code}$ \1\&{then}\6
\&{begin} \37$\\{fin\_col}\K\\{true}$;\5
\&{return};\6
\&{end};\2\6
$\\{init\_span}(\|p)$;\6
\&{end};\2\6
$\\{align\_state}\K1000000$;\5
\X406:Get the next non-blank non-call token\X;\6
$\\{cur\_align}\K\|p$;\5
\\{init\_col};\5
$\\{fin\_col}\K\\{false}$;\6
\4\\{exit}: \37\&{end};\par
\fi

\M792. \P$\X792:If the preamble list has been traversed, check that the row has
ended\X\S$\6
\&{if} $(\|p=\\{null})\W(\\{extra\_info}(\\{cur\_align})<\\{cr\_code})$ \1%
\&{then}\6
\&{if} $\\{cur\_loop}\I\\{null}$ \1\&{then}\5
\X793:Lengthen the preamble periodically\X\6
\4\&{else} \&{begin} \37$\\{print\_err}(\.{"Extra\ alignment\ tab\ has\ been\
changed\ to\ "})$;\5
$\\{print\_esc}(\.{"cr"})$;\5
$\\{help3}(\.{"You\ have\ given\ more\ \\span\ or\ \&\ marks\ than\ there\
were"})$\6
$(\.{"in\ the\ preamble\ to\ the\ \\halign\ or\ \\valign\ now\ in\
progress."})$\6
$(\.{"So\ I\'ll\ assume\ that\ you\ meant\ to\ type\ \\cr\ instead."})$;\5
$\\{extra\_info}(\\{cur\_align})\K\\{cr\_code}$;\5
\\{error};\6
\&{end}\2\2\par
\U section~791.\fi

\M793. \P$\X793:Lengthen the preamble periodically\X\S$\6
\&{begin} \37$\\{link}(\|q)\K\\{new\_null\_box}$;\5
$\|p\K\\{link}(\|q)$;\C{a new alignrecord}\6
$\\{info}(\|p)\K\\{end\_span}$;\5
$\\{width}(\|p)\K\\{null\_flag}$;\5
$\\{cur\_loop}\K\\{link}(\\{cur\_loop})$;\5
\X794:Copy the templates from node \\{cur\_loop} into node \|p\X;\6
$\\{cur\_loop}\K\\{link}(\\{cur\_loop})$;\5
$\\{link}(\|p)\K\\{new\_glue}(\\{glue\_ptr}(\\{cur\_loop}))$;\6
\&{end}\par
\U section~792.\fi

\M794. \P$\X794:Copy the templates from node \\{cur\_loop} into node \|p\X\S$\6
$\|q\K\\{hold\_head}$;\5
$\|r\K\\{u\_part}(\\{cur\_loop})$;\6
\&{while} $\|r\I\\{null}$ \1\&{do}\6
\&{begin} \37$\\{link}(\|q)\K\\{get\_avail}$;\5
$\|q\K\\{link}(\|q)$;\5
$\\{info}(\|q)\K\\{info}(\|r)$;\5
$\|r\K\\{link}(\|r)$;\6
\&{end};\2\6
$\\{link}(\|q)\K\\{null}$;\5
$\\{u\_part}(\|p)\K\\{link}(\\{hold\_head})$;\5
$\|q\K\\{hold\_head}$;\5
$\|r\K\\{v\_part}(\\{cur\_loop})$;\6
\&{while} $\|r\I\\{null}$ \1\&{do}\6
\&{begin} \37$\\{link}(\|q)\K\\{get\_avail}$;\5
$\|q\K\\{link}(\|q)$;\5
$\\{info}(\|q)\K\\{info}(\|r)$;\5
$\|r\K\\{link}(\|r)$;\6
\&{end};\2\6
$\\{link}(\|q)\K\\{null}$;\5
$\\{v\_part}(\|p)\K\\{link}(\\{hold\_head})$\par
\U section~793.\fi

\M795. \P$\X795:Copy the tabskip glue between columns\X\S$\6
$\\{tail\_append}(\\{new\_glue}(\\{glue\_ptr}(\\{link}(\\{cur\_align}))))$;\5
$\\{subtype}(\\{tail})\K\\{tab\_skip\_code}+1$\par
\U section~791.\fi

\M796. \P$\X796:Package an unset box for the current column and record its
width\X\S$\6
\&{begin} \37\&{if} $\\{mode}=-\\{hmode}$ \1\&{then}\6
\&{begin} \37$\\{adjust\_tail}\K\\{cur\_tail}$;\5
$\|u\K\\{hpack}(\\{link}(\\{head}),\39\\{natural})$;\5
$\|w\K\\{width}(\|u)$;\5
$\\{cur\_tail}\K\\{adjust\_tail}$;\5
$\\{adjust\_tail}\K\\{null}$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\|u\K\\{vpackage}(\\{link}(\\{head}),\39\\{natural},%
\390)$;\5
$\|w\K\\{height}(\|u)$;\6
\&{end};\2\6
$\|n\K\\{min\_quarterword}$;\C{this represents a span count of 1}\6
\&{if} $\\{cur\_span}\I\\{cur\_align}$ \1\&{then}\5
\X798:Update width entry for spanned columns\X\6
\4\&{else} \&{if} $\|w>\\{width}(\\{cur\_align})$ \1\&{then}\5
$\\{width}(\\{cur\_align})\K\|w$;\2\2\6
$\\{type}(\|u)\K\\{unset\_node}$;\5
$\\{span\_count}(\|u)\K\|n$;\6
\X659:Determine the stretch order\X;\6
$\\{glue\_order}(\|u)\K\|o$;\5
$\\{glue\_stretch}(\|u)\K\\{total\_stretch}[\|o]$;\6
\X665:Determine the shrink order\X;\6
$\\{glue\_sign}(\|u)\K\|o$;\5
$\\{glue\_shrink}(\|u)\K\\{total\_shrink}[\|o]$;\6
\\{pop\_nest};\5
$\\{link}(\\{tail})\K\|u$;\5
$\\{tail}\K\|u$;\6
\&{end}\par
\U section~791.\fi

\M797. A span node is a 2-word record containing \\{width}, \\{info}, and %
\\{link}
fields. The \\{link} field is not really a link, it indicates the number of
spanned columns; the \\{info} field points to a span node for the same
starting column, having a greater extent of spanning, or to \\{end\_span},
which has the largest possible \\{link} field; the \\{width} field holds the
largest natural width corresponding to a particular set of spanned columns.

A list of the maximum widths so far, for spanned columns starting at a
given column, begins with the \\{info} field of the alignrecord for that
column.

\Y\P\D \37$\\{span\_node\_size}=2$\C{number of \\{mem} words for a span node}%
\par
\Y\P$\4\X790:Initialize the special list heads and constant nodes\X\mathrel{+}%
\S$\6
$\\{link}(\\{end\_span})\K\\{max\_quarterword}+1$;\5
$\\{info}(\\{end\_span})\K\\{null}$;\par
\fi

\M798. \P$\X798:Update width entry for spanned columns\X\S$\6
\&{begin} \37$\|q\K\\{cur\_span}$;\6
\1\&{repeat} \37$\\{incr}(\|n)$;\5
$\|q\K\\{link}(\\{link}(\|q))$;\6
\4\&{until}\5
$\|q=\\{cur\_align}$;\2\6
\&{if} $\|n>\\{max\_quarterword}$ \1\&{then}\5
$\\{confusion}(\.{"256\ spans"})$;\C{this can happen, but won't}\2\6
$\|q\K\\{cur\_span}$;\6
\&{while} $\\{link}(\\{info}(\|q))<\|n$ \1\&{do}\5
$\|q\K\\{info}(\|q)$;\2\6
\&{if} $\\{link}(\\{info}(\|q))>\|n$ \1\&{then}\6
\&{begin} \37$\|s\K\\{get\_node}(\\{span\_node\_size})$;\5
$\\{info}(\|s)\K\\{info}(\|q)$;\5
$\\{link}(\|s)\K\|n$;\5
$\\{info}(\|q)\K\|s$;\5
$\\{width}(\|s)\K\|w$;\6
\&{end}\6
\4\&{else} \&{if} $\\{width}(\\{info}(\|q))<\|w$ \1\&{then}\5
$\\{width}(\\{info}(\|q))\K\|w$;\2\2\6
\&{end}\par
\U section~796.\fi

\M799. At the end of a row, we append an unset box to the current vlist (for
\.{\\halign}) or the current hlist (for \.{\\valign}). This unset box
contains the unset boxes for the columns, separated by the tabskip glue.
Everything will be set later.

\Y\P\4\&{procedure}\1\  \37\\{fin\_row};\6
\4\&{var} \37\|p: \37\\{pointer};\C{the new unset box}\2\6
\&{begin} \37\&{if} $\\{mode}=-\\{hmode}$ \1\&{then}\6
\&{begin} \37$\|p\K\\{hpack}(\\{link}(\\{head}),\39\\{natural})$;\5
\\{pop\_nest};\5
$\\{append\_to\_vlist}(\|p)$;\6
\&{if} $\\{cur\_head}\I\\{cur\_tail}$ \1\&{then}\6
\&{begin} \37$\\{link}(\\{tail})\K\\{link}(\\{cur\_head})$;\5
$\\{tail}\K\\{cur\_tail}$;\6
\&{end};\2\6
\&{end}\6
\4\&{else} \&{begin} \37$\|p\K\\{vpack}(\\{link}(\\{head}),\39\\{natural})$;\5
\\{pop\_nest};\5
$\\{link}(\\{tail})\K\|p$;\5
$\\{tail}\K\|p$;\5
$\\{space\_factor}\K1000$;\6
\&{end};\2\6
$\\{type}(\|p)\K\\{unset\_node}$;\5
$\\{glue\_stretch}(\|p)\K0$;\6
\&{if} $\\{every\_cr}\I\\{null}$ \1\&{then}\5
$\\{begin\_token\_list}(\\{every\_cr},\39\\{every\_cr\_text})$;\2\6
\\{align\_peek};\6
\&{end};\C{note that $\\{glue\_shrink}(\|p)=0$ since $\\{glue\_shrink}\S%
\\{shift\_amount}$}\par
\fi

\M800. Finally, we will reach the end of the alignment, and we can breathe a
sigh of relief that memory hasn't overflowed. All the unset boxes will now be
set so that the columns line up, taking due account of spanned columns.

\Y\P\4\&{procedure}\1\  \37\\{do\_assignments};\5
\\{forward};\5
\hbox{\2}\6
\4\&{procedure}\1\  \37\\{resume\_after\_display};\5
\\{forward};\5
\hbox{\2}\6
\4\&{procedure}\1\  \37\\{build\_page};\5
\\{forward};\5
\hbox{\2}\6
\4\&{procedure}\1\  \37\\{fin\_align};\6
\4\&{var} \37$\|p,\39\|q,\39\|r,\39\|s,\39\|u,\39\|v$: \37\\{pointer};%
\C{registers for the list operations}\6
$\|t,\39\|w$: \37\\{scaled};\C{width of column}\6
\|o: \37\\{scaled};\C{shift offset for unset boxes}\6
\|n: \37\\{halfword};\C{matching span amount}\6
\\{rule\_save}: \37\\{scaled};\C{temporary storage for \\{overfull\_rule}}\2\6
\&{begin} \37\&{if} $\\{cur\_group}\I\\{align\_group}$ \1\&{then}\5
$\\{confusion}(\.{"align1"})$;\2\6
\\{unsave};\C{that \\{align\_group} was for individual entries}\6
\&{if} $\\{cur\_group}\I\\{align\_group}$ \1\&{then}\5
$\\{confusion}(\.{"align0"})$;\2\6
\\{unsave};\C{that \\{align\_group} was for the whole alignment}\6
\&{if} $\\{nest}[\\{nest\_ptr}-1].\\{mode\_field}=\\{mmode}$ \1\&{then}\5
$\|o\K\\{display\_indent}$\6
\4\&{else} $\|o\K0$;\2\6
\X801:Go through the preamble list, determining the column widths and changing
the alignrecords to dummy unset boxes\X;\6
\X804:Package the preamble list, to determine the actual tabskip glue amounts,
and let \|p point to this prototype box\X;\6
\X805:Set the glue in all the unset boxes of the current list\X;\6
$\\{flush\_node\_list}(\|p)$;\5
\\{pop\_alignment};\5
\X812:Insert the \(c)current list into its environment\X;\6
\&{end};\6
\hbox{\4}\X785:Declare the procedure called \\{align\_peek}\X\par
\fi

\M801. It's time now to dismantle the preamble list and to compute the column
widths. Let $w_{ij}$ be the maximum of the natural widths of all entries
that span columns $i$ through $j$, inclusive. The alignrecord for column~$i$
contains $w_{ii}$ in its \\{width} field, and there is also a linked list of
the nonzero $w_{ij}$ for increasing $j$, accessible via the \\{info} field;
these span nodes contain the value $j-i-1+\\{min\_quarterword}$ in their
\\{link} fields. The values of $w_{ii}$ were initialized to \\{null\_flag},
which
we regard as $-\infty$.

The final column widths are defined by the formula
$$w_j=\max_{1\L i\L j}\biggl( w_{ij}-\sum_{i\L k<j}(t_k+w_k)\biggr),$$
where $t_k$ is the natural width of the tabskip glue between columns
$k$ and~$k+1$. However, if $w_{ij}=-\infty$ for all \|i in the range
$1\L\|i\L\|j$ (i.e., if every entry that involved column~\|j also involved
column~$\|j+1$), we let $w_j=0$, and we zero out the tabskip glue after
column~\|j.

\TeX\ computes these values by using the following scheme: First $w_1=w_{11}$.
Then replace $w_{2j}$ by $\max(w_{2j},w_{1j}-t_1-w_1)$, for all $j>1$.
Then $w_2=w_{22}$. Then replace $w_{3j}$ by $\max(w_{3j},w_{2j}-t_2-w_2)$
for all $j>2$; and so on. If any $w_j$ turns out to be $-\infty$, its
value is changed to zero and so is the next tabskip.

\Y\P$\4\X801:Go through the preamble list, determining the column widths and
changing the alignrecords to dummy unset boxes\X\S$\6
$\|q\K\\{link}(\\{preamble})$;\6
\1\&{repeat} \37$\\{flush\_list}(\\{u\_part}(\|q))$;\5
$\\{flush\_list}(\\{v\_part}(\|q))$;\5
$\|p\K\\{link}(\\{link}(\|q))$;\6
\&{if} $\\{width}(\|q)=\\{null\_flag}$ \1\&{then}\5
\X802:Nullify $\\{width}(\|q)$ and the tabskip glue following this column\X;\2\6
\&{if} $\\{info}(\|q)\I\\{end\_span}$ \1\&{then}\5
\X803:Merge the widths in the span nodes of \|q with those of \|p, destroying
the span nodes of \|q\X;\2\6
$\\{type}(\|q)\K\\{unset\_node}$;\5
$\\{span\_count}(\|q)\K\\{min\_quarterword}$;\5
$\\{height}(\|q)\K0$;\5
$\\{depth}(\|q)\K0$;\5
$\\{glue\_order}(\|q)\K\\{normal}$;\5
$\\{glue\_sign}(\|q)\K\\{normal}$;\5
$\\{glue\_stretch}(\|q)\K0$;\5
$\\{glue\_shrink}(\|q)\K0$;\5
$\|q\K\|p$;\6
\4\&{until}\5
$\|q=\\{null}$\2\par
\U section~800.\fi

\M802. \P$\X802:Nullify $\\{width}(\|q)$ and the tabskip glue following this
column\X\S$\6
\&{begin} \37$\\{width}(\|q)\K0$;\5
$\|r\K\\{link}(\|q)$;\5
$\|s\K\\{glue\_ptr}(\|r)$;\6
\&{if} $\|s\I\\{zero\_glue}$ \1\&{then}\6
\&{begin} \37$\\{add\_glue\_ref}(\\{zero\_glue})$;\5
$\\{delete\_glue\_ref}(\|s)$;\5
$\\{glue\_ptr}(\|r)\K\\{zero\_glue}$;\6
\&{end};\2\6
\&{end}\par
\U section~801.\fi

\M803. Merging of two span-node lists is a typical exercise in the manipulation
of
linearly linked data structures. The essential invariant in the following
 \&{repeat}  loop is that we want to dispense with node \|r, in \|q's list,
and \|u is its successor; all nodes of \|p's list up to and including \|s
have been processed, and the successor of \|s matches \|r or precedes \|r
or follows \|r, according as $\\{link}(\|r)=\|n$ or $\\{link}(\|r)>\|n$ or $%
\\{link}(\|r)<\|n$.

\Y\P$\4\X803:Merge the widths in the span nodes of \|q with those of \|p,
destroying the span nodes of \|q\X\S$\6
\&{begin} \37$\|t\K\\{width}(\|q)+\\{width}(\\{glue\_ptr}(\\{link}(\|q)))$;\5
$\|r\K\\{info}(\|q)$;\5
$\|s\K\\{end\_span}$;\5
$\\{info}(\|s)\K\|p$;\5
$\|n\K\\{min\_quarterword}+1$;\6
\1\&{repeat} \37$\\{width}(\|r)\K\\{width}(\|r)-\|t$;\5
$\|u\K\\{info}(\|r)$;\6
\&{while} $\\{link}(\|r)>\|n$ \1\&{do}\6
\&{begin} \37$\|s\K\\{info}(\|s)$;\5
$\|n\K\\{link}(\\{info}(\|s))+1$;\6
\&{end};\2\6
\&{if} $\\{link}(\|r)<\|n$ \1\&{then}\6
\&{begin} \37$\\{info}(\|r)\K\\{info}(\|s)$;\5
$\\{info}(\|s)\K\|r$;\5
$\\{decr}(\\{link}(\|r))$;\5
$\|s\K\|r$;\6
\&{end}\6
\4\&{else} \&{begin} \37\&{if} $\\{width}(\|r)>\\{width}(\\{info}(\|s))$ \1%
\&{then}\5
$\\{width}(\\{info}(\|s))\K\\{width}(\|r)$;\2\6
$\\{free\_node}(\|r,\39\\{span\_node\_size})$;\6
\&{end};\2\6
$\|r\K\|u$;\6
\4\&{until}\5
$\|r=\\{end\_span}$;\2\6
\&{end}\par
\U section~801.\fi

\M804. Now the preamble list has been converted to a list of alternating unset
boxes and tabskip glue, where the box widths are equal to the final
column sizes. In case of \.{\\valign}, we change the widths to heights,
so that a correct error message will be produced if the alignment is
overfull or underfull.

\Y\P$\4\X804:Package the preamble list, to determine the actual tabskip glue
amounts, and let \|p point to this prototype box\X\S$\6
$\\{save\_ptr}\K\\{save\_ptr}-2$;\5
$\\{pack\_begin\_line}\K-\\{mode\_line}$;\6
\&{if} $\\{mode}=-\\{vmode}$ \1\&{then}\6
\&{begin} \37$\\{rule\_save}\K\\{overfull\_rule}$;\5
$\\{overfull\_rule}\K0$;\C{prevent rule from being packaged}\6
$\|p\K\\{hpack}(\\{preamble},\39\\{saved}(1),\39\\{saved}(0))$;\5
$\\{overfull\_rule}\K\\{rule\_save}$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\|q\K\\{link}(\\{preamble})$;\6
\1\&{repeat} \37$\\{height}(\|q)\K\\{width}(\|q)$;\5
$\\{width}(\|q)\K0$;\5
$\|q\K\\{link}(\\{link}(\|q))$;\6
\4\&{until}\5
$\|q=\\{null}$;\2\6
$\|p\K\\{vpack}(\\{preamble},\39\\{saved}(1),\39\\{saved}(0))$;\5
$\|q\K\\{link}(\\{preamble})$;\6
\1\&{repeat} \37$\\{width}(\|q)\K\\{height}(\|q)$;\5
$\\{height}(\|q)\K0$;\5
$\|q\K\\{link}(\\{link}(\|q))$;\6
\4\&{until}\5
$\|q=\\{null}$;\2\6
\&{end};\2\6
$\\{pack\_begin\_line}\K0$\par
\U section~800.\fi

\M805. \P$\X805:Set the glue in all the unset boxes of the current list\X\S$\6
$\|q\K\\{link}(\\{head})$;\6
\&{while} $\|q\I\\{null}$ \1\&{do}\6
\&{begin} \37\&{if} $\\{type}(\|q)=\\{unset\_node}$ \1\&{then}\5
\X807:Set the unset box \|q and the unset boxes in it\X\6
\4\&{else} \&{if} $\\{type}(\|q)=\\{rule\_node}$ \1\&{then}\5
\X806:Make the running dimensions in rule \|q extend to the boundaries of the
alignment\X;\2\2\6
$\|q\K\\{link}(\|q)$;\6
\&{end}\2\par
\U section~800.\fi

\M806. \P$\X806:Make the running dimensions in rule \|q extend to the
boundaries of the alignment\X\S$\6
\&{begin} \37\&{if} $\\{is\_running}(\\{width}(\|q))$ \1\&{then}\5
$\\{width}(\|q)\K\\{width}(\|p)$;\2\6
\&{if} $\\{is\_running}(\\{height}(\|q))$ \1\&{then}\5
$\\{height}(\|q)\K\\{height}(\|p)$;\2\6
\&{if} $\\{is\_running}(\\{depth}(\|q))$ \1\&{then}\5
$\\{depth}(\|q)\K\\{depth}(\|p)$;\2\6
\&{end}\par
\U section~805.\fi

\M807. The unset box \|q represents a row that contains one or more unset
boxes,
depending on how soon \.{\\cr} occurred in that row.

\Y\P$\4\X807:Set the unset box \|q and the unset boxes in it\X\S$\6
\&{begin} \37\&{if} $\\{mode}=-\\{vmode}$ \1\&{then}\6
\&{begin} \37$\\{type}(\|q)\K\\{hlist\_node}$;\5
$\\{width}(\|q)\K\\{width}(\|p)$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{type}(\|q)\K\\{vlist\_node}$;\5
$\\{height}(\|q)\K\\{height}(\|p)$;\6
\&{end};\2\6
$\\{glue\_order}(\|q)\K\\{glue\_order}(\|p)$;\5
$\\{glue\_sign}(\|q)\K\\{glue\_sign}(\|p)$;\5
$\\{glue\_set}(\|q)\K\\{glue\_set}(\|p)$;\5
$\\{shift\_amount}(\|q)\K\|o$;\5
$\|r\K\\{link}(\\{list\_ptr}(\|q))$;\5
$\|s\K\\{link}(\\{list\_ptr}(\|p))$;\6
\1\&{repeat} \37\X808:Set the glue in node \|r and change it from an unset node%
\X;\6
$\|r\K\\{link}(\\{link}(\|r))$;\5
$\|s\K\\{link}(\\{link}(\|s))$;\6
\4\&{until}\5
$\|r=\\{null}$;\2\6
\&{end}\par
\U section~805.\fi

\M808. A box made from spanned columns will be followed by tabskip glue nodes
and
by empty boxes as if there were no spanning. This permits perfect alignment
of subsequent entries, and it prevents values that depend on floating point
arithmetic from entering into the dimensions of any boxes.

\Y\P$\4\X808:Set the glue in node \|r and change it from an unset node\X\S$\6
$\|n\K\\{span\_count}(\|r)$;\5
$\|t\K\\{width}(\|s)$;\5
$\|w\K\|t$;\5
$\|u\K\\{hold\_head}$;\6
\&{while} $\|n>\\{min\_quarterword}$ \1\&{do}\6
\&{begin} \37$\\{decr}(\|n)$;\5
\X809:Append tabskip glue and an empty box to list \|u, and update \|s and \|t
as the prototype nodes are passed\X;\6
\&{end};\2\6
\&{if} $\\{mode}=-\\{vmode}$ \1\&{then}\5
\X810:Make the unset node \|r into an \\{hlist\_node} of width \|w, setting the
glue as if the width were \|t\X\6
\4\&{else} \X811:Make the unset node \|r into a \\{vlist\_node} of height \|w,
setting the glue as if the height were \|t\X;\2\6
$\\{shift\_amount}(\|r)\K0$;\6
\&{if} $\|u\I\\{hold\_head}$ \1\&{then}\C{append blank boxes to account for
spanned nodes}\6
\&{begin} \37$\\{link}(\|u)\K\\{link}(\|r)$;\5
$\\{link}(\|r)\K\\{link}(\\{hold\_head})$;\5
$\|r\K\|u$;\6
\&{end}\2\par
\U section~807.\fi

\M809. \P$\X809:Append tabskip glue and an empty box to list \|u, and update %
\|s and \|t as the prototype nodes are passed\X\S$\6
$\|s\K\\{link}(\|s)$;\5
$\|v\K\\{glue\_ptr}(\|s)$;\5
$\\{link}(\|u)\K\\{new\_glue}(\|v)$;\5
$\|u\K\\{link}(\|u)$;\5
$\\{subtype}(\|u)\K\\{tab\_skip\_code}+1$;\5
$\|t\K\|t+\\{width}(\|v)$;\6
\&{if} $\\{glue\_sign}(\|p)=\\{stretching}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{stretch\_order}(\|v)=\\{glue\_order}(\|p)$ \1\&{then}\5
$\|t\K\|t+\\{round}(\\{float}(\\{glue\_set}(\|p))\ast\\{stretch}(\|v))$;\2\6
\&{end}\6
\4\&{else} \&{if} $\\{glue\_sign}(\|p)=\\{shrinking}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{shrink\_order}(\|v)=\\{glue\_order}(\|p)$ \1\&{then}\5
$\|t\K\|t-\\{round}(\\{float}(\\{glue\_set}(\|p))\ast\\{shrink}(\|v))$;\2\6
\&{end};\2\2\6
$\|s\K\\{link}(\|s)$;\5
$\\{link}(\|u)\K\\{new\_null\_box}$;\5
$\|u\K\\{link}(\|u)$;\5
$\|t\K\|t+\\{width}(\|s)$;\6
\&{if} $\\{mode}=-\\{vmode}$ \1\&{then}\5
$\\{width}(\|u)\K\\{width}(\|s)$\ \&{else} \&{begin} \37$\\{type}(\|u)\K%
\\{vlist\_node}$;\5
$\\{height}(\|u)\K\\{width}(\|s)$;\6
\&{end}\2\par
\U section~808.\fi

\M810. \P$\X810:Make the unset node \|r into an \\{hlist\_node} of width \|w,
setting the glue as if the width were \|t\X\S$\6
\&{begin} \37$\\{height}(\|r)\K\\{height}(\|q)$;\5
$\\{depth}(\|r)\K\\{depth}(\|q)$;\6
\&{if} $\|t=\\{width}(\|r)$ \1\&{then}\6
\&{begin} \37$\\{glue\_sign}(\|r)\K\\{normal}$;\5
$\\{glue\_order}(\|r)\K\\{normal}$;\5
$\\{set\_glue\_ratio\_zero}(\\{glue\_set}(\|r))$;\6
\&{end}\6
\4\&{else} \&{if} $\|t>\\{width}(\|r)$ \1\&{then}\6
\&{begin} \37$\\{glue\_sign}(\|r)\K\\{stretching}$;\6
\&{if} $\\{glue\_stretch}(\|r)=0$ \1\&{then}\5
$\\{set\_glue\_ratio\_zero}(\\{glue\_set}(\|r))$\6
\4\&{else} $\\{glue\_set}(\|r)\K\\{unfloat}((\|t-\\{width}(\|r))/\\{glue%
\_stretch}(\|r))$;\2\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{glue\_order}(\|r)\K\\{glue\_sign}(\|r)$;\5
$\\{glue\_sign}(\|r)\K\\{shrinking}$;\6
\&{if} $\\{glue\_shrink}(\|r)=0$ \1\&{then}\5
$\\{set\_glue\_ratio\_zero}(\\{glue\_set}(\|r))$\6
\4\&{else} \&{if} $(\\{glue\_order}(\|r)=\\{normal})\W(\\{width}(\|r)-\|t>%
\\{glue\_shrink}(\|r))$ \1\&{then}\5
$\\{set\_glue\_ratio\_one}(\\{glue\_set}(\|r))$\6
\4\&{else} $\\{glue\_set}(\|r)\K\\{unfloat}((\\{width}(\|r)-\|t)/\\{glue%
\_shrink}(\|r))$;\2\2\6
\&{end};\2\2\6
$\\{width}(\|r)\K\|w$;\5
$\\{type}(\|r)\K\\{hlist\_node}$;\6
\&{end}\par
\U section~808.\fi

\M811. \P$\X811:Make the unset node \|r into a \\{vlist\_node} of height \|w,
setting the glue as if the height were \|t\X\S$\6
\&{begin} \37$\\{width}(\|r)\K\\{width}(\|q)$;\6
\&{if} $\|t=\\{height}(\|r)$ \1\&{then}\6
\&{begin} \37$\\{glue\_sign}(\|r)\K\\{normal}$;\5
$\\{glue\_order}(\|r)\K\\{normal}$;\5
$\\{set\_glue\_ratio\_zero}(\\{glue\_set}(\|r))$;\6
\&{end}\6
\4\&{else} \&{if} $\|t>\\{height}(\|r)$ \1\&{then}\6
\&{begin} \37$\\{glue\_sign}(\|r)\K\\{stretching}$;\6
\&{if} $\\{glue\_stretch}(\|r)=0$ \1\&{then}\5
$\\{set\_glue\_ratio\_zero}(\\{glue\_set}(\|r))$\6
\4\&{else} $\\{glue\_set}(\|r)\K\\{unfloat}((\|t-\\{height}(\|r))/\\{glue%
\_stretch}(\|r))$;\2\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{glue\_order}(\|r)\K\\{glue\_sign}(\|r)$;\5
$\\{glue\_sign}(\|r)\K\\{shrinking}$;\6
\&{if} $\\{glue\_shrink}(\|r)=0$ \1\&{then}\5
$\\{set\_glue\_ratio\_zero}(\\{glue\_set}(\|r))$\6
\4\&{else} \&{if} $(\\{glue\_order}(\|r)=\\{normal})\W(\\{height}(\|r)-\|t>%
\\{glue\_shrink}(\|r))$ \1\&{then}\5
$\\{set\_glue\_ratio\_one}(\\{glue\_set}(\|r))$\6
\4\&{else} $\\{glue\_set}(\|r)\K\\{unfloat}((\\{height}(\|r)-\|t)/\\{glue%
\_shrink}(\|r))$;\2\2\6
\&{end};\2\2\6
$\\{height}(\|r)\K\|w$;\5
$\\{type}(\|r)\K\\{vlist\_node}$;\6
\&{end}\par
\U section~808.\fi

\M812. We now have a completed alignment, in the list that starts at \\{head}
and ends at \\{tail}. This list will be merged with the one that encloses
it. (In case the enclosing mode is \\{mmode}, for displayed formulas,
we will need to insert glue before and after the display; that part of the
program will be deferred until we're more familiar with such operations.)

\Y\P$\4\X812:Insert the \(c)current list into its environment\X\S$\6
$\|t\K\\{aux}$;\5
$\|p\K\\{link}(\\{head})$;\5
$\|q\K\\{tail}$;\5
\\{pop\_nest};\6
\&{if} $\\{mode}=\\{mmode}$ \1\&{then}\5
\X1206:Finish an alignment in a display\X\6
\4\&{else} \&{begin} \37$\\{aux}\K\|t$;\5
$\\{link}(\\{tail})\K\|p$;\6
\&{if} $\|p\I\\{null}$ \1\&{then}\5
$\\{tail}\K\|q$;\2\6
\&{if} $\\{mode}=\\{vmode}$ \1\&{then}\5
\\{build\_page};\2\6
\&{end}\2\par
\U section~800.\fi

\N813.  \[38] Breaking paragraphs into lines.
We come now to what is probably the most interesting algorithm of \TeX:
the mechanism for choosing the ``best possible'' breakpoints that yield
the individual lines of a paragraph. \TeX's line-breaking algorithm takes
a given horizontal list and converts it to a sequence of boxes that are
appended to the current vertical list. In the course of doing this, it
creates a special data structure containing three kinds of records that are
not used elsewhere in \TeX. Such nodes are created while a paragraph is
being processed, and they are destroyed afterwards; thus, the other parts
of \TeX\ do not need to know anything about how line-breaking is done.

The method used here is based on an approach devised by Michael F. Plass and
the author in 1977, subsequently generalized and improved by the same two
people in 1980. A detailed discussion appears in {\sl SOFTWARE---Practice
\AM\ Experience \bf11} (1981), 1119--1184, where it is shown that the
line-breaking problem can be regarded as a special case of the problem of
computing the shortest path in an acyclic network. The cited paper includes
numerous examples and describes the history of line breaking as it has been
practiced by printers through the ages. The present implementation adds two
new ideas to the algorithm of 1980: memory space requirements are considerably
reduced by using smaller records for inactive nodes than for active ones,
and arithmetic overflow is avoided by using ``delta distances'' instead of
keeping track of the total distance from the beginning of the paragraph to the
current point.

\fi

\M814. The \\{line\_break} procedure should be invoked only in horizontal mode;
it
leaves that mode and places its output into the current vlist of the
enclosing vertical mode (or internal vertical mode).
There is one explicit parameter:  \\{final\_widow\_penalty} is the amount of
additional penalty to be inserted before the final line of the paragraph.

There are also a number of implicit parameters: The hlist to be broken
starts at $\\{link}(\\{head})$, and it is nonempty. The value of \\{prev\_graf}
in the
enclosing semantic level tells where the paragraph should begin in the
sequence of line numbers, in case hanging indentation or \.{\\parshape}
are in use; \\{prev\_graf} is zero unless this paragraph is being continued
after a displayed formula.  Other implicit parameters, such as the
\\{par\_shape\_ptr} and various penalties to use for hyphenation, etc., appear
in \\{eqtb}.

After \\{line\_break} has acted, it will have updated the current vlist and the
value of \\{prev\_graf}. Furthermore, the global variable \\{just\_box} will
point to the final box created by \\{line\_break}, so that the width of this
line can be ascertained when it is necessary to decide whether to use
\\{above\_display\_skip} or \\{above\_display\_short\_skip} before a displayed
formula.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{just\_box}: \37\\{pointer};\C{the \\{hlist\_node} for the last line of the
new paragraph}\par
\fi

\M815. Since \\{line\_break} is a rather lengthy procedure---sort of a small
world unto
itself---we must build it up little by little, somewhat more cautiously
than we have done with the simpler procedures of \TeX. Here is the
general outline.

\Y\P\hbox{\4}\X826:Declare subprocedures for \\{line\_break}\X \6
\4\&{procedure}\1\  \37$\\{line\_break}(\\{final\_widow\_penalty}:%
\\{integer})$;\6
\4\&{label} \37$\\{done},\39\\{done1},\39\\{done2},\39\\{done3},\39\\{done4}$;\6
\4\&{var} \37\X862:Local variables for line breaking\X\2\6
\&{begin} \37$\\{pack\_begin\_line}\K\\{mode\_line}$;\C{this is for
over/underfull box messages}\6
\X816:Get ready to start line breaking\X;\6
\X863:Find optimal breakpoints\X;\6
\X876:Break the paragraph at the chosen breakpoints, justify the resulting
lines to the correct widths, and append them to the current vertical list\X;\6
\X865:Clean up the memory by removing the break nodes\X;\6
$\\{pack\_begin\_line}\K0$;\6
\&{end};\par
\fi

\M816. The first task is to move the list from \\{head} to \\{temp\_head} and
go
into the enclosing semantic level. We also append the \.{\\parfillskip}
glue to the end of the paragraph, removing a space (or other glue node) if
it was there, since spaces usually precede blank lines and instances of
`\.{\$\$}'. The \\{par\_fill\_skip} is preceded by an infinite penalty, so
it will never be considered as a potential breakpoint.

This code assumes that a \\{glue\_node} and a \\{penalty\_node} occupy the
same number of words in \\{mem}.

\Y\P$\4\X816:Get ready to start line breaking\X\S$\6
$\\{link}(\\{temp\_head})\K\\{link}(\\{head})$;\6
\&{if} $\\{is\_char\_node}(\\{tail})$ \1\&{then}\5
$\\{tail\_append}(\\{new\_penalty}(\\{inf\_penalty}))$\6
\4\&{else} \&{if} $\\{type}(\\{tail})\I\\{glue\_node}$ \1\&{then}\5
$\\{tail\_append}(\\{new\_penalty}(\\{inf\_penalty}))$\6
\4\&{else} \&{begin} \37$\\{type}(\\{tail})\K\\{penalty\_node}$;\5
$\\{delete\_glue\_ref}(\\{glue\_ptr}(\\{tail}))$;\5
$\\{flush\_node\_list}(\\{leader\_ptr}(\\{tail}))$;\5
$\\{penalty}(\\{tail})\K\\{inf\_penalty}$;\6
\&{end};\2\2\6
$\\{link}(\\{tail})\K\\{new\_param\_glue}(\\{par\_fill\_skip\_code})$;\5
\\{pop\_nest};\par
\A sections~827, 834, and~848.
\U section~815.\fi

\M817. When looking for optimal line breaks, \TeX\ creates a ``break node'' for
each break that is {\sl feasible}, in the sense that there is a way to end
a line at the given place without requiring any line to stretch more than
a given tolerance. A break node is characterized by three things: the position
of the break (which is a pointer to a \\{glue\_node}, \\{math\_node}, %
\\{penalty\_node},
or \\{disc\_node}); the ordinal number of the line that will follow this
breakpoint; and the fitness classification of the line that has just
ended, i.e., \\{tight\_fit}, \\{decent\_fit}, \\{loose\_fit}, or \\{very\_loose%
\_fit}.

\Y\P\D \37$\\{tight\_fit}=3$\C{fitness classification for lines shrinking 0.5
to 1.0 of their 	shrinkability}\par
\P\D \37$\\{loose\_fit}=1$\C{fitness classification for lines stretching 0.5 to
1.0 of their 	stretchability}\par
\P\D \37$\\{very\_loose\_fit}=0$\C{fitness classification for lines stretching
more than 	their stretchability}\par
\P\D \37$\\{decent\_fit}=2$\C{fitness classification for all other lines}\par
\fi

\M818. The algorithm essentially determines the best possible way to achieve
each feasible combination of position, line, and fitness. Thus, it answers
questions like, ``What is the best way to break the opening part of the
paragraph so that the fourth line is a tight line ending at such-and-such
a place?'' However, the fact that all lines are to be the same length
after a certain point makes it possible to regard all sufficiently large
line numbers as equivalent, when the looseness parameter is zero, and this
makes it possible for the algorithm to save space and time.

An ``active node'' and a ``passive node'' are created in \\{mem} for each
feasible breakpoint that needs to be considered. Active nodes are three
words long and passive nodes are two words long. We need active nodes only
for breakpoints near the place in the paragraph that is currently being
examined, so they are recycled within a comparatively short time after
they are created.

\fi

\M819. An active node for a given breakpoint contains six fields:

\yskip\hang\\{link} points to the next node in the list of active nodes; the
last active node has $\\{link}=\\{last\_active}$.

\yskip\hang\\{break\_node} points to the passive node associated with this
breakpoint.

\yskip\hang\\{line\_number} is the number of the line that follows this
breakpoint.

\yskip\hang\\{fitness} is the fitness classification of the line ending at this
breakpoint.

\yskip\hang\\{type} is either \\{hyphenated} or \\{unhyphenated}, depending on
whether this breakpoint is a \\{disc\_node}.

\yskip\hang\\{total\_demerits} is the minimum possible sum of demerits over all
lines leading from the beginning of the paragraph to this breakpoint.

\yskip\noindent
The value of $\\{link}(\\{active})$ points to the first active node on a linked
list
of all currently active nodes. This list is in order by \\{line\_number},
except that nodes with $\\{line\_number}>\\{easy\_line}$ may be in any order
relative
to each other.

\Y\P\D \37$\\{active\_node\_size}=3$\C{number of words in active nodes}\par
\P\D \37$\\{fitness}\S\\{subtype}$\C{$\\{very\_loose\_fit}\to\\{tight\_fit}$ on
final line for this break}\par
\P\D \37$\\{break\_node}\S\\{rlink}$\C{pointer to the corresponding passive
node}\par
\P\D \37$\\{line\_number}\S\\{llink}$\C{line that begins at this breakpoint}\par
\P\D \37$\\{total\_demerits}(\#)\S\\{mem}[\#+2].\\{int}$\C{the quantity that %
\TeX\ minimizes}\par
\P\D \37$\\{unhyphenated}=0$\C{the \\{type} of a normal active break node}\par
\P\D \37$\\{hyphenated}=1$\C{the \\{type} of an active node that breaks at a %
\\{disc\_node}}\par
\P\D \37$\\{last\_active}\S\\{active}$\C{the active list ends where it begins}%
\par
\fi

\M820. \P$\X790:Initialize the special list heads and constant nodes\X%
\mathrel{+}\S$\6
$\\{type}(\\{last\_active})\K\\{hyphenated}$;\5
$\\{line\_number}(\\{last\_active})\K\\{max\_halfword}$;\5
$\\{subtype}(\\{last\_active})\K0$;\C{the \\{subtype} is never examined by the
algorithm}\par
\fi

\M821. The passive node for a given breakpoint contains only four fields:

\yskip\hang\\{link} points to the passive node created just before this one,
if any, otherwise it is \\{null}.

\yskip\hang\\{cur\_break} points to the position of this breakpoint in the
horizontal list for the paragraph being broken.

\yskip\hang\\{prev\_break} points to the passive node that should precede this
one in an optimal path to this breakpoint.

\yskip\hang\\{serial} is equal to \|n if this passive node is the \|nth
one created during the current pass. (This field is used only when
printing out detailed statistics about the line-breaking calculations.)

\yskip\noindent
There is a global variable called \\{passive} that points to the most
recently created passive node. Another global variable, \\{printed\_node},
is used to help print out the paragraph when detailed information about
the line-breaking computation is being displayed.

\Y\P\D \37$\\{passive\_node\_size}=2$\C{number of words in passive nodes}\par
\P\D \37$\\{cur\_break}\S\\{rlink}$\C{in passive node, points to position of
this breakpoint}\par
\P\D \37$\\{prev\_break}\S\\{llink}$\C{points to passive node that should
precede this one}\par
\P\D \37$\\{serial}\S\\{info}$\C{serial number for symbolic identification}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{passive}: \37\\{pointer};\C{most recent node on passive list}\6
\4\\{printed\_node}: \37\\{pointer};\C{most recent node that has been printed}\6
\4\\{pass\_number}: \37\\{halfword};\C{the number of passive nodes allocated on
this pass}\par
\fi

\M822. The active list also contains ``delta'' nodes that help the algorithm
compute the badness of individual lines. Such nodes appear only between two
active nodes, and they have $\\{type}=\\{delta\_node}$. If \|p and \|r are
active nodes
and if \|q is a delta node between them, so that $\\{link}(\|p)=\|q$ and $%
\\{link}(\|q)=\|r$,
then \|q tells the space difference between lines in the horizontal list that
start after breakpoint \|p and lines that start after breakpoint \|r. In
other words, if we know the length of the line that starts after \|p and
ends at our current position, then the corresponding length of the line that
starts after \|r is obtained by adding the amounts in node~\|q. A delta node
contains six scaled numbers, since it must record the net change in glue
stretchability with respect to all orders of infinity. The natural width
difference appears in $\\{mem}[\|q+1].\\{sc}$; the stretch differences in units
of
pt, fil, fill, and filll appear in $\\{mem}[\|q+2\to\|q+5].\\{sc}$; and the
shrink difference
appears in $\\{mem}[\|q+6].\\{sc}$. The \\{subtype} field of a delta node is
not used.

\Y\P\D \37$\\{delta\_node\_size}=7$\C{number of words in a delta node}\par
\P\D \37$\\{delta\_node}=2$\C{\\{type} field in a delta node}\par
\fi

\M823. As the algorithm runs, it maintains a set of six delta-like registers
for the length of the line following the first active breakpoint to the
current position in the given hlist. When it makes a pass through the
active list, it also maintains a similar set of six registers for the
length following the active breakpoint of current interest. A third set
holds the length of an empty line (namely, the sum of \.{\\leftskip} and
\.{\\rightskip}); and a fourth set is used to create new delta nodes.

When we pass a delta node we want to do operations like `\ignorespaces \&{for}
$\|k\K1\mathrel{\&{to}}6$ \&{do} $\\{cur\_active\_width}[\|k]\K\\{cur\_active%
\_width}[\|k]+\\{mem}[\|q+\|k].\\{sc}$', and we
want to do this without the overhead of  \&{for}  loops. The \\{do\_all\_six}
macro makes such six-tuples convenient.

\Y\P\D \37$\\{do\_all\_six}(\#)\S\#(1)$;\5
$\#(2)$;\5
$\#(3)$;\5
$\#(4)$;\5
$\#(5)$;\5
$\#(6)$\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{active\_width}: \37\&{array} $[1\to6]$ \1\&{of}\5
\\{scaled};\C{distance from first active node to~\\{cur\_p}}\2\6
\4\\{cur\_active\_width}: \37\&{array} $[1\to6]$ \1\&{of}\5
\\{scaled};\C{distance from current active node}\2\6
\4\\{background}: \37\&{array} $[1\to6]$ \1\&{of}\5
\\{scaled};\C{length of an ``empty'' line}\2\6
\4\\{break\_width}: \37\&{array} $[1\to6]$ \1\&{of}\5
\\{scaled};\C{length being computed after current break}\2\par
\fi

\M824. Let's state the principles of the delta nodes more precisely and
concisely,
so that the following programs will be less obscure. For each legal
breakpoint~\|p in the paragraph, we define two quantities $\alpha(p)$ and
$\beta(p)$ such that the length of material in a line from breakpoint~\|p
to breakpoint~\|q is $\gamma+\beta(q)-\alpha(p)$, for some fixed $\gamma$.
Intuitively, $\alpha(p)$ and $\beta(q)$ are the total length of material from
the beginning of the paragraph to a point ``after'' a break at \|p and to a
point ``before'' a break at \|q; and $\gamma$ is the width of an empty line,
namely the length contributed by \.{\\leftskip} and \.{\\rightskip}.

Suppose, for example, that the paragraph consists entirely of alternating
boxes and glue skips; let the boxes have widths $x_1\ldots x_n$ and
let the skips have widths $y_1\ldots y_n$, so that the paragraph can be
represented by $x_1y_1\ldots x_ny_n$. Let $p_i$ be the legal breakpoint
at $y_i$; then $\alpha(p_i)=x_1+y_1+\cdots+x_i+y_i$, and $\beta(p_i)=
x_1+y_1+\cdots+x_i$. To check this, note that the length of material from
$p_2$ to $p_5$, say, is $\gamma+x_3+y_3+x_4+y_4+x_5=\gamma+\beta(p_5)
-\alpha(p_2)$.

The quantities $\alpha$, $\beta$, $\gamma$ involve glue stretchability and
shrinkability as well as a natural width. If we were to compute $\alpha(p)$
and $\beta(p)$ for each \|p, we would need multiple precision arithmetic, and
the multiprecise numbers would have to be kept in the active nodes.
\TeX\ avoids this problem by working entirely with relative differences
or ``deltas.'' Suppose, for example, that the active list contains
$a_1\,\delta_1\,a_2\,\delta_2\,a_3$, where the \|a's are active breakpoints
and the $\delta$'s are delta nodes. Then $\delta_1=\alpha(a_1)-\alpha(a_2)$
and $\delta_2=\alpha(a_2)-\alpha(a_3)$. If the line breaking algorithm is
currently positioned at some other breakpoint \|p, the \\{active\_width} array
contains the value $\gamma+\beta(p)-\alpha(a_1)$. If we are scanning through
the list of active nodes and considering a tentative line that runs from
$a_2$ to~\|p, say, the \\{cur\_active\_width} array will contain the value
$\gamma+\beta(p)-\alpha(a_2)$. Thus, when we move from $a_2$ to $a_3$,
we want to add $\alpha(a_2)-\alpha(a_3)$ to \\{cur\_active\_width}; and this
is just $\delta_2$, which appears in the active list between $a_2$ and
$a_3$. The \\{background} array contains $\gamma$. The \\{break\_width} array
will be used to calculate values of new delta nodes when the active
list is being updated.

\fi

\M825. Glue nodes in a horizontal list that is being paragraphed are not
supposed to
include ``infinite'' shrinkability; that is why the algorithm maintains
four registers for stretching but only one for shrinking. If the user tries to
introduce infinite shrinkability, the shrinkability will be reset to finite
and an error message will be issued. A boolean variable \\{no\_shrink\_error%
\_yet}
prevents this error message from appearing more than once per paragraph.

\Y\P\D \37$\\{check\_shrinkage}(\#)\S$\1\6
\&{if} $(\\{shrink\_order}(\#)\I\\{normal})\W(\\{shrink}(\#)\I0)$ \1\&{then}\6
\&{begin} \37$\#\K\\{finite\_shrink}(\#)$;\6
\&{end}\2\2\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{no\_shrink\_error\_yet}: \37\\{boolean};\C{have we complained about
infinite shrinkage?}\par
\fi

\M826. \P$\X826:Declare subprocedures for \\{line\_break}\X\S$\6
\4\&{function}\1\  \37$\\{finite\_shrink}(\|p:\\{pointer})$: \37\\{pointer};%
\C{recovers from infinite shrinkage}\6
\4\&{var} \37\|q: \37\\{pointer};\C{new glue specification}\2\6
\&{begin} \37\&{if} $\\{no\_shrink\_error\_yet}$ \1\&{then}\6
\&{begin} \37$\\{no\_shrink\_error\_yet}\K\\{false}$;\5
$\\{print\_err}(\.{"Infinite\ glue\ shrinkage\ found\ in\ a\ paragraph"})$;\5
$\\{help5}(\.{"The\ paragraph\ just\ ended\ includes\ some\ glue\ that\ has"})$%
\6
$(\.{"infinite\ shrinkability,\ e.g.,\ \`\\hskip\ 0pt\ minus\ 1fil\'."})$\6
$(\.{"Such\ glue\ doesn\'t\ belong\ there---it\ allows\ a\ paragraph"})$\6
$(\.{"of\ any\ length\ to\ fit\ on\ one\ line.\ But\ it\'s\ safe\ to\
proceed,"})$\6
$(\.{"since\ the\ offensive\ shrinkability\ has\ been\ made\ finite."})$;\5
\\{error};\6
\&{end};\2\6
$\|q\K\\{new\_spec}(\|p)$;\5
$\\{shrink\_order}(\|q)\K\\{normal}$;\5
$\\{delete\_glue\_ref}(\|p)$;\5
$\\{finite\_shrink}\K\|q$;\6
\&{end};\par
\A sections~829, 877, and~895.
\U section~815.\fi

\M827. \P$\X816:Get ready to start line breaking\X\mathrel{+}\S$\6
$\\{no\_shrink\_error\_yet}\K\\{true}$;\6
$\\{check\_shrinkage}(\\{left\_skip})$;\5
$\\{check\_shrinkage}(\\{right\_skip})$;\6
$\|q\K\\{left\_skip}$;\5
$\|r\K\\{right\_skip}$;\5
$\\{background}[1]\K\\{width}(\|q)+\\{width}(\|r)$;\6
$\\{background}[2]\K0$;\5
$\\{background}[3]\K0$;\5
$\\{background}[4]\K0$;\5
$\\{background}[5]\K0$;\6
$\\{background}[2+\\{stretch\_order}(\|q)]\K\\{stretch}(\|q)$;\6
$\\{background}[2+\\{stretch\_order}(\|r)]\K\30\\{background}[2+\\{stretch%
\_order}(\|r)]+\\{stretch}(\|r)$;\6
$\\{background}[6]\K\\{shrink}(\|q)+\\{shrink}(\|r)$;\par
\fi

\M828. A pointer variable \\{cur\_p} runs through the given horizontal list as
we look
for breakpoints. This variable is global, since it is used both by \\{line%
\_break}
and by its subprocedure \\{try\_break}.

Another global variable called \\{threshold} is used to determine the
feasibility
of individual lines: breakpoints are feasible if there is a way to reach
them without creating lines whose badness exceeds \\{threshold}.  (The
badness is compared to \\{threshold} before penalties are added, so that
penalty values do not affect the feasibility of breakpoints, except that
no break is allowed when the penalty is 10000 or more.) If \\{threshold}
is 10000 or more, all legal breaks are considered feasible, since the
\\{badness} function specified above never returns a value greater than~10000.

Two passes might be made through the paragraph in an attempt to find at
least one set of feasible breakpoints. On the first pass, we have
$\\{threshold}=\\{pretolerance}$ and $\\{second\_pass}=\\{false}$. If this pass
fails to find a
feasible solution, \\{threshold} is set to \\{tolerance}, \\{second\_pass} is
set
\\{true}, and an attempt is made to hyphenate as many words as possible.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{cur\_p}: \37\\{pointer};\C{the current breakpoint under consideration}\6
\4\\{second\_pass}: \37\\{boolean};\C{is this our second attempt to break this
paragraph?}\6
\4\\{threshold}: \37\\{integer};\C{maximum badness on feasible lines}\par
\fi

\M829. The heart of the line-breaking procedure is `\\{try\_break}', a
subroutine
that tests if the current breakpoint \\{cur\_p} is feasible, by running
through the active list to see what lines of text can be made from active
nodes to~\\{cur\_p}.  If feasible breaks are possible, new break nodes are
created.  If \\{cur\_p} is too far from an active node, that node is
deactivated.

The parameter \\{pi} to \\{try\_break} is the penalty associated
with a break at \\{cur\_p}; we have $\\{pi}=\\{eject\_penalty}$ if the break is
forced,
and $\\{pi}=\\{inf\_penalty}$ if the break is illegal.

The other parameter, \\{break\_type}, is set to \\{hyphenated} or %
\\{unhyphenated},
depending on whether or not the current break is at a \\{disc\_node}. The
end of a paragraph is also regarded as `\\{hyphenated}'; this case is
distinguishable by the condition $\\{cur\_p}=\\{null}$.

\Y\P\D \37$\\{copy\_to\_cur\_active}(\#)\S\\{cur\_active\_width}[\#]\K\\{active%
\_width}[\#]$\par
\P\D \37$\\{deactivate}=60$\C{go here when node \|r should be deactivated}\par
\Y\P$\4\X826:Declare subprocedures for \\{line\_break}\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{try\_break}(\\{pi}:\\{integer};\,\35\\{break\_type}:%
\\{small\_number})$;\6
\4\&{label} \37$\\{exit},\39\\{done},\39\\{done1},\39\\{continue},\39%
\\{deactivate}$;\6
\4\&{var} \37\|r: \37\\{pointer};\C{runs through the active list}\6
\\{prev\_r}: \37\\{pointer};\C{stays a step behind \|r}\6
\\{old\_l}: \37\\{halfword};\C{maximum line number in current equivalence class
of lines}\6
\\{no\_break\_yet}: \37\\{boolean};\C{have we found a feasible break at \\{cur%
\_p}?}\6
\X830:Other local variables for \\{try\_break}\X\2\6
\&{begin} \37\X831:Make sure that \\{pi} is in the proper range\X;\6
$\\{no\_break\_yet}\K\\{true}$;\5
$\\{prev\_r}\K\\{active}$;\5
$\\{old\_l}\K0$;\5
$\\{do\_all\_six}(\\{copy\_to\_cur\_active})$;\6
\~ \1\&{loop}\ \&{begin} \37\\{continue}: \37$\|r\K\\{link}(\\{prev\_r})$;\5
\X832:If node \|r is of type \\{delta\_node}, update \\{cur\_active\_width},
set \\{prev\_r} and \\{prev\_prev\_r}, then \&{goto} \\{continue}\X;\6
\X835:If a line number class has ended, create new active nodes for the best
feasible breaks in that class; then \&{return} if $\|r=\\{last\_active}$,
otherwise compute the new \\{line\_width}\X;\6
\X851:Consider the demerits for a line from \|r to \\{cur\_p}; deactivate node %
\|r if it should no longer be active; then \&{goto} \\{continue} if a line from
\|r to \\{cur\_p} is infeasible, otherwise record a new feasible break\X;\6
\&{end};\2\6
\4\\{exit}: \37\&{stat} \37\X858:Update the value of \\{printed\_node} for
symbolic displays\X\ \&{tats}\6
\&{end};\par
\fi

\M830. \P$\X830:Other local variables for \\{try\_break}\X\S$\6
\4\\{prev\_prev\_r}: \37\\{pointer};\C{a step behind \\{prev\_r}, if $\\{type}(%
\\{prev\_r})=\\{delta\_node}$}\6
\4\|s: \37\\{pointer};\C{runs through nodes ahead of \\{cur\_p}}\6
\4\|q: \37\\{pointer};\C{points to a new node being created}\6
\4\|v: \37\\{pointer};\C{points to a glue specification or a node ahead of %
\\{cur\_p}}\6
\4\|t: \37\\{integer};\C{node count, if \\{cur\_p} is a discretionary node}\6
\4\|f: \37\\{internal\_font\_number};\C{used in character width calculation}\6
\4\|l: \37\\{halfword};\C{line number of current active node}\6
\4\\{node\_r\_stays\_active}: \37\\{boolean};\C{should node \|r remain in the
active list?}\6
\4\\{line\_width}: \37\\{scaled};\C{the current line will be justified to this
width}\6
\4\\{fit\_class}: \37$\\{very\_loose\_fit}\to\\{tight\_fit}$;\C{possible
fitness class of test line}\6
\4\|b: \37\\{halfword};\C{badness of test line}\6
\4\|d: \37\\{integer};\C{demerits of test line}\6
\4\\{artificial\_badness}: \37\\{boolean};\C{has \|b been forced to zero?}\6
\4\\{save\_link}: \37\\{pointer};\C{temporarily holds value of $\\{link}(\\{cur%
\_p})$}\6
\4\\{shortfall}: \37\\{scaled};\C{used in badness calculations}\par
\U section~829.\fi

\M831. \P$\X831:Make sure that \\{pi} is in the proper range\X\S$\6
\&{if} $\\{abs}(\\{pi})\G\\{inf\_penalty}$ \1\&{then}\6
\&{if} $\\{pi}>0$ \1\&{then}\5
\&{return}\C{this breakpoint is inhibited by infinite penalty}\6
\4\&{else} $\\{pi}\K\\{eject\_penalty}$\C{this breakpoint will be forced}\2\2%
\par
\U section~829.\fi

\M832. The following code uses the fact that $\\{type}(\\{last\_active})\I%
\\{delta\_node}$.

\Y\P\D \37$\\{update\_width}(\#)\S\30\\{cur\_active\_width}[\#]\K\\{cur\_active%
\_width}[\#]+\\{mem}[\|r+\#].\\{sc}$\par
\Y\P$\4\X832:If node \|r is of type \\{delta\_node}, update \\{cur\_active%
\_width}, set \\{prev\_r} and \\{prev\_prev\_r}, then \&{goto} \\{continue}\X%
\S$\6
\&{if} $\\{type}(\|r)=\\{delta\_node}$ \1\&{then}\6
\&{begin} \37$\\{do\_all\_six}(\\{update\_width})$;\5
$\\{prev\_prev\_r}\K\\{prev\_r}$;\5
$\\{prev\_r}\K\|r$;\5
\&{goto} \37\\{continue};\6
\&{end}\2\par
\U section~829.\fi

\M833. As we consider various ways to end a line at \\{cur\_p}, in a given line
number
class, we keep track of the best total demerits known, in an array with
one entry for each of the fitness classifications. For example,
$\\{minimal\_demerits}[\\{tight\_fit}]$ contains the fewest total demerits of
feasible
line breaks ending at \\{cur\_p} with a \\{tight\_fit} line; $\\{best\_place}[%
\\{tight\_fit}]$
points to the passive node for the break before~\\{cur\_p} that achieves such
an optimum; and $\\{best\_pl\_line}[\\{tight\_fit}]$ is the \\{line\_number}
field in the
active node corresponding to $\\{best\_place}[\\{tight\_fit}]$. When no
feasible break
sequence is known, the \\{minimal\_demerits} entries will be equal to
\\{awful\_bad}, which is $2↑{30}-1$. Another variable, \\{minimum\_demerits},
keeps track of the smallest value in the \\{minimal\_demerits} array.

\Y\P\D \37$\\{awful\_bad}\S\O{7777777777}$\C{more than a billion demerits}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{minimal\_demerits}: \37\&{array} $[\\{very\_loose\_fit}\to\\{tight\_fit}]$
\1\&{of}\5
\\{scaled};\C{best total 	demerits known for current line class and position,
given the fitness}\2\6
\4\\{minimum\_demerits}: \37\\{scaled};\C{best total demerits known for current
line class 	and position}\6
\4\\{best\_place}: \37\&{array} $[\\{very\_loose\_fit}\to\\{tight\_fit}]$ \1%
\&{of}\5
\\{pointer};\C{how to achieve 	\\{minimal\_demerits}}\2\6
\4\\{best\_pl\_line}: \37\&{array} $[\\{very\_loose\_fit}\to\\{tight\_fit}]$ \1%
\&{of}\5
\\{halfword};\C{corresponding 	line number}\2\par
\fi

\M834. \P$\X816:Get ready to start line breaking\X\mathrel{+}\S$\6
$\\{minimum\_demerits}\K\\{awful\_bad}$;\5
$\\{minimal\_demerits}[\\{tight\_fit}]\K\\{awful\_bad}$;\5
$\\{minimal\_demerits}[\\{decent\_fit}]\K\\{awful\_bad}$;\5
$\\{minimal\_demerits}[\\{loose\_fit}]\K\\{awful\_bad}$;\5
$\\{minimal\_demerits}[\\{very\_loose\_fit}]\K\\{awful\_bad}$;\par
\fi

\M835. The first part of the following code is part of \TeX's inner loop, so
we don't want to waste any time. The current active node, namely node \|r,
contains the line number that will be considered next. At the end of the
list we have arranged the data structure so that $\|r=\\{last\_active}$ and
$\\{line\_number}(\\{last\_active})>\\{old\_l}$.

\Y\P$\4\X835:If a line number class has ended, create new active nodes for the
best feasible breaks in that class; then \&{return} if $\|r=\\{last\_active}$,
otherwise compute the new \\{line\_width}\X\S$\6
\&{begin} \37$\|l\K\\{line\_number}(\|r)$;\6
\&{if} $\|l>\\{old\_l}$ \1\&{then}\6
\&{begin} \37\C{now we are no longer in the inner loop}\6
\&{if} $(\\{minimum\_demerits}<\\{awful\_bad})\W\30((\\{old\_l}\I\\{easy%
\_line})\V(\|r=\\{last\_active}))$ \1\&{then}\5
\X836:Create new active nodes for the best feasible breaks just found\X;\2\6
\&{if} $\|r=\\{last\_active}$ \1\&{then}\5
\&{return};\2\6
\X850:Compute the new line width\X;\6
\&{end};\2\6
\&{end}\par
\U section~829.\fi

\M836. It is not necessary to create new active nodes having $\\{minimal%
\_demerits}>\\{minimum\_demerits}+\\{abs}(\\{adj\_demerits})$, since such
active nodes will never
be chosen in the final paragraph breaks. This observation allows us to
omit a substantial number of feasible breakpoints from further consideration.

\Y\P$\4\X836:Create new active nodes for the best feasible breaks just found\X%
\S$\6
\&{begin} \37\&{if} $\\{no\_break\_yet}$ \1\&{then}\5
\X837:Compute the values of \\{break\_width}\X;\2\6
\X843:Insert a delta node to prepare for breaks at \\{cur\_p}\X;\6
$\\{minimum\_demerits}\K\\{minimum\_demerits}+\\{abs}(\\{adj\_demerits})$;\6
\&{for} $\\{fit\_class}\K\\{very\_loose\_fit}\mathrel{\&{to}}\\{tight\_fit}$ \1%
\&{do}\6
\&{begin} \37\&{if} $\\{minimal\_demerits}[\\{fit\_class}]\L\\{minimum%
\_demerits}$ \1\&{then}\5
\X845:Insert a new active node from $\\{best\_place}[\\{fit\_class}]$ to \\{cur%
\_p}\X;\2\6
$\\{minimal\_demerits}[\\{fit\_class}]\K\\{awful\_bad}$;\6
\&{end};\2\6
$\\{minimum\_demerits}\K\\{awful\_bad}$;\5
\X844:Insert a delta node to prepare for the next active node\X;\6
\&{end}\par
\U section~835.\fi

\M837. When we insert a new active node for a break at \\{cur\_p}, suppose this
new node is to be placed just before active node \|a; then we essentially
want to insert `$\delta\,\\{cur\_p}\,\delta↑\prime$' before \|a, where
$\delta=\alpha(a)-\alpha(\\{cur\_p})$ and $\delta↑\prime=\alpha(\\{cur\_p})-%
\alpha(a)$
in the notation explained above.  The \\{cur\_active\_width} array now holds
$\gamma+\beta(\\{cur\_p})-\alpha(a)$; so $\delta$ can be obtained by
subtracting \\{cur\_active\_width} from the quantity $\gamma+\beta(\\{cur\_p})-
\alpha(\\{cur\_p})$. The latter quantity can be regarded as the length of a
line ``from \\{cur\_p} to \\{cur\_p}''; we call it the \\{break\_width} at %
\\{cur\_p}.

The \\{break\_width} is usually negative, since it consists of the background
(which is normally zero) minus the width of nodes following~\\{cur\_p} that are
eliminated after a break. If, for example, node \\{cur\_p} is a glue node, the
width of this glue is subtracted from the background; and we also look
ahead to eliminate all subsequent glue and penalty and kern and math
nodes, subtracting their widths as well.

Kern nodes for accents are treated specially: They do not
disappear at a line break.

\Y\P\D \37$\\{set\_break\_width\_to\_background}(\#)\S\\{break\_width}[\#]\K%
\\{background}[\#]$\par
\Y\P$\4\X837:Compute the values of \\{break\_width}\X\S$\6
\&{begin} \37$\\{no\_break\_yet}\K\\{false}$;\5
$\\{do\_all\_six}(\\{set\_break\_width\_to\_background})$;\5
$\|s\K\\{cur\_p}$;\6
\&{if} $\\{break\_type}>\\{unhyphenated}$ \1\&{then}\6
\&{if} $\\{cur\_p}\I\\{null}$ \1\&{then}\5
\X840:Compute the discretionary \\{break\_width} values\X;\2\2\6
\&{while} $\|s\I\\{null}$ \1\&{do}\6
\&{begin} \37\&{if} $\\{is\_char\_node}(\|s)$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
\&{case} $\\{type}(\|s)$ \1\&{of}\6
\4\\{glue\_node}: \37\X838:Subtract glue from \\{break\_width}\X;\6
\4\\{penalty\_node}: \37\\{do\_nothing};\6
\4$\\{math\_node},\39\\{kern\_node}$: \37\&{if} $\\{subtype}(\|s)=\\{acc%
\_kern}$ \1\&{then}\5
\&{goto} \37\\{done}\6
\4\&{else} $\\{break\_width}[1]\K\\{break\_width}[1]-\\{width}(\|s)$;\2\6
\4\&{othercases} \37\&{goto} \37\\{done}\2\6
\&{endcases};\6
$\|s\K\\{link}(\|s)$;\6
\&{end};\2\6
\4\\{done}: \37\&{end}\par
\U section~836.\fi

\M838. \P$\X838:Subtract glue from \\{break\_width}\X\S$\6
\&{begin} \37$\|v\K\\{glue\_ptr}(\|s)$;\5
$\\{break\_width}[1]\K\\{break\_width}[1]-\\{width}(\|v)$;\5
$\\{break\_width}[2+\\{stretch\_order}(\|v)]\K\\{break\_width}[2+\\{stretch%
\_order}(\|v)]-\\{stretch}(\|v)$;\5
$\\{break\_width}[6]\K\\{break\_width}[6]-\\{shrink}(\|v)$;\6
\&{end}\par
\U section~837.\fi

\M839. When \\{cur\_p} is a discretionary break, the length of a line ``from %
\\{cur\_p} to
\\{cur\_p}'' has to be defined properly so that the other calculations work
out.
Suppose that the pre-break text at \\{cur\_p} has length $l_0$, the post-break
text has length $l_1$, and the replacement text has length \|l. Suppose
also that \|q is the node following the replacement text. Then length of a
line from \\{cur\_p} to \|q will be computed as $\gamma+\beta(q)-\alpha(\\{cur%
\_p})$,
where $\beta(q)=\beta(\\{cur\_p})-l_0+l$. The actual length will be the
background
plus $l_1$, so the length from \\{cur\_p} to \\{cur\_p} should be $%
\gamma+l_0+l_1-l$,
minus the length of nodes that will be discarded after the discretionary break.

The value of $l_0$ need not be computed, since \\{line\_break} will put
it into the global variable \\{disc\_width} before calling \\{try\_break}.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{disc\_width}: \37\\{scaled};\C{the length of discretionary material
preceding a break}\par
\fi

\M840. \P$\X840:Compute the discretionary \\{break\_width} values\X\S$\6
\&{begin} \37$\|t\K\\{replace\_count}(\\{cur\_p})$;\5
$\|v\K\\{cur\_p}$;\5
$\|s\K\\{post\_break}(\\{cur\_p})$;\6
\&{while} $\|t>0$ \1\&{do}\6
\&{begin} \37$\\{decr}(\|t)$;\5
$\|v\K\\{link}(\|v)$;\5
\X841\*:Subtract the width of node \|v from \\{break\_width}\X;\6
\&{end};\2\6
\&{while} $\|s\I\\{null}$ \1\&{do}\6
\&{begin} \37\X842\*:Add the width of node \|s to \\{break\_width} and increase
\|t, unless it's discardable\X;\6
$\|s\K\\{link}(\|s)$;\6
\&{end};\2\6
$\\{break\_width}[1]\K\\{break\_width}[1]+\\{disc\_width}$;\6
\&{if} $\|t=0$ \1\&{then}\5
$\|s\K\\{link}(\|v)$;\C{more nodes may also be discardable after the break}\2\6
\&{end}\par
\U section~837.\fi

\M841\*. Replacement texts and discretionary texts are supposed to contain
only character nodes, kern nodes, ligature nodes, and box or rule nodes.

\Y\P$\4\X841\*:Subtract the width of node \|v from \\{break\_width}\X\S$\6
\&{if} $\\{is\_char\_node}(\|v)$ \1\&{then}\6
\&{begin} \37\&{if} $\\{is\_xchar\_node}(\|v)$ \1\&{then}\6
\&{begin} \37$\|v\K\\{link}(\|v)$;\5
$\\{decr}(\|t)$;\C{an xchar counts as two chars}\6
\&{end};\2\6
$\|f\K\\{font}(\|v)$;\5
$\\{break\_width}[1]\K\\{break\_width}[1]-\\{char\_width}(\|f)(\\{char\_info}(%
\|f)(\\{character}(\|v)))$;\6
\&{end}\6
\4\&{else} \&{case} $\\{type}(\|v)$ \1\&{of}\6
\4\\{ligature\_node}: \37\&{begin} \37$\|f\K\\{font}(\\{lig\_char}(\|v))$;\6
$\\{break\_width}[1]\K\30\\{break\_width}[1]-\\{char\_width}(\|f)(\\{char%
\_info}(\|f)(\\{character}(\\{lig\_char}(\|v))))$;\6
\&{end};\6
\4$\\{hlist\_node},\39\\{vlist\_node},\39\\{rule\_node},\39\\{kern\_node}$: %
\37$\\{break\_width}[1]\K\\{break\_width}[1]-\\{width}(\|v)$;\6
\4\&{othercases} \37$\\{confusion}(\.{"disc1"})$\2\6
\&{endcases}\2\par
\U section~840.\fi

\M842\*. \P$\X842\*:Add the width of node \|s to \\{break\_width} and increase %
\|t, unless it's discardable\X\S$\6
\&{if} $\\{is\_char\_node}(\|s)$ \1\&{then}\6
\&{begin} \37$\\{bypass\_xchar}(\|s)$;\5
$\|f\K\\{font}(\|s)$;\5
$\\{break\_width}[1]\K\30\\{break\_width}[1]+\\{char\_width}(\|f)(\\{char%
\_info}(\|f)(\\{character}(\|s)))$;\6
\&{end}\6
\4\&{else} \&{case} $\\{type}(\|s)$ \1\&{of}\6
\4\\{ligature\_node}: \37\&{begin} \37$\|f\K\\{font}(\\{lig\_char}(\|s))$;\5
$\\{break\_width}[1]\K\\{break\_width}[1]+\\{char\_width}(\|f)(\\{char\_info}(%
\|f)(\\{character}(\\{lig\_char}(\|s))))$;\6
\&{end};\6
\4$\\{hlist\_node},\39\\{vlist\_node},\39\\{rule\_node}$: \37$\\{break%
\_width}[1]\K\\{break\_width}[1]+\\{width}(\|s)$;\6
\4\\{kern\_node}: \37\&{if} $(\|t=0)\W(\\{subtype}(\|s)\I\\{acc\_kern})$ \1%
\&{then}\5
$\|t\K-1$\C{discardable}\6
\4\&{else} $\\{break\_width}[1]\K\\{break\_width}[1]+\\{width}(\|s)$;\2\6
\4\&{othercases} \37$\\{confusion}(\.{"disc2"})$\2\6
\&{endcases};\2\6
$\\{incr}(\|t)$\par
\U section~840.\fi

\M843. We use the fact that $\\{type}(\\{active})\I\\{delta\_node}$.

\Y\P\D \37$\\{convert\_to\_break\_width}(\#)\S\30\\{mem}[\\{prev\_r}+\#].\\{sc}%
\K\30\hbox{\hskip10pt}\\{mem}[\\{prev\_r}+\#].\\{sc}-\\{cur\_active\_width}[%
\#]+\\{break\_width}[\#]$\par
\P\D \37$\\{store\_break\_width}(\#)\S\\{active\_width}[\#]\K\\{break\_width}[%
\#]$\par
\P\D \37$\\{new\_delta\_to\_break\_width}(\#)\S\30\\{mem}[\|q+\#].\\{sc}\K%
\\{break\_width}[\#]-\\{cur\_active\_width}[\#]$\par
\Y\P$\4\X843:Insert a delta node to prepare for breaks at \\{cur\_p}\X\S$\6
\&{if} $\\{type}(\\{prev\_r})=\\{delta\_node}$ \1\&{then}\C{modify an existing
delta node}\6
\&{begin} \37$\\{do\_all\_six}(\\{convert\_to\_break\_width})$;\6
\&{end}\6
\4\&{else} \&{if} $\\{prev\_r}=\\{active}$ \1\&{then}\C{no delta node needed at
the beginning}\6
\&{begin} \37$\\{do\_all\_six}(\\{store\_break\_width})$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\|q\K\\{get\_node}(\\{delta\_node\_size})$;\5
$\\{link}(\|q)\K\|r$;\5
$\\{type}(\|q)\K\\{delta\_node}$;\6
$\\{subtype}(\|q)\K0$;\C{the \\{subtype} is not used}\6
$\\{do\_all\_six}(\\{new\_delta\_to\_break\_width})$;\5
$\\{link}(\\{prev\_r})\K\|q$;\5
$\\{prev\_prev\_r}\K\\{prev\_r}$;\5
$\\{prev\_r}\K\|q$;\6
\&{end}\2\2\par
\U section~836.\fi

\M844. When the following code is performed, we will have just inserted at
least one active node before \|r, so $\\{type}(\\{prev\_r})\I\\{delta\_node}$.

\Y\P\D \37$\\{new\_delta\_from\_break\_width}(\#)\S\30\\{mem}[\|q+\#].\\{sc}\K%
\\{cur\_active\_width}[\#]-\\{break\_width}[\#]$\par
\Y\P$\4\X844:Insert a delta node to prepare for the next active node\X\S$\6
\&{if} $\|r\I\\{last\_active}$ \1\&{then}\6
\&{begin} \37$\|q\K\\{get\_node}(\\{delta\_node\_size})$;\5
$\\{link}(\|q)\K\|r$;\5
$\\{type}(\|q)\K\\{delta\_node}$;\6
$\\{subtype}(\|q)\K0$;\C{the \\{subtype} is not used}\6
$\\{do\_all\_six}(\\{new\_delta\_from\_break\_width})$;\5
$\\{link}(\\{prev\_r})\K\|q$;\5
$\\{prev\_prev\_r}\K\\{prev\_r}$;\5
$\\{prev\_r}\K\|q$;\6
\&{end}\2\par
\U section~836.\fi

\M845. When we create an active node, we also create the corresponding
passive node.

\Y\P$\4\X845:Insert a new active node from $\\{best\_place}[\\{fit\_class}]$ to
\\{cur\_p}\X\S$\6
\&{begin} \37$\|q\K\\{get\_node}(\\{passive\_node\_size})$;\5
$\\{link}(\|q)\K\\{passive}$;\5
$\\{passive}\K\|q$;\5
$\\{cur\_break}(\|q)\K\\{cur\_p}$;\6
\&{stat} \37$\\{incr}(\\{pass\_number})$;\5
$\\{serial}(\|q)\K\\{pass\_number}$;\ \&{tats}\6
$\\{prev\_break}(\|q)\K\\{best\_place}[\\{fit\_class}]$;\6
$\|q\K\\{get\_node}(\\{active\_node\_size})$;\5
$\\{break\_node}(\|q)\K\\{passive}$;\5
$\\{line\_number}(\|q)\K\\{best\_pl\_line}[\\{fit\_class}]+1$;\5
$\\{fitness}(\|q)\K\\{fit\_class}$;\5
$\\{type}(\|q)\K\\{break\_type}$;\5
$\\{total\_demerits}(\|q)\K\\{minimal\_demerits}[\\{fit\_class}]$;\5
$\\{link}(\|q)\K\|r$;\5
$\\{link}(\\{prev\_r})\K\|q$;\5
$\\{prev\_r}\K\|q$;\6
\&{stat} \37\&{if} $\\{tracing\_paragraphs}>0$ \1\&{then}\5
\X846:Print a symbolic description of the new break node\X;\2\6
\&{tats}\6
\&{end}\par
\U section~836.\fi

\M846. \P$\X846:Print a symbolic description of the new break node\X\S$\6
\&{begin} \37$\\{print\_nl}(\.{"@@"})$;\5
$\\{print\_int}(\\{serial}(\\{passive}))$;\5
$\\{print}(\.{":\ line\ "})$;\5
$\\{print\_int}(\\{line\_number}(\|q)-1)$;\5
$\\{print\_char}(\.{"."})$;\5
$\\{print\_int}(\\{fit\_class})$;\6
\&{if} $\\{break\_type}=\\{hyphenated}$ \1\&{then}\5
$\\{print\_char}(\.{"-"})$;\2\6
$\\{print}(\.{"\ t="})$;\5
$\\{print\_int}(\\{total\_demerits}(\|q))$;\5
$\\{print}(\.{"\ ->\ @@"})$;\6
\&{if} $\\{prev\_break}(\\{passive})=\\{null}$ \1\&{then}\5
$\\{print\_char}(\.{"0"})$\6
\4\&{else} $\\{print\_int}(\\{serial}(\\{prev\_break}(\\{passive})))$;\2\6
\&{end}\par
\U section~845.\fi

\M847. The length of lines depends on whether the user has specified
\.{\\parshape} or \.{\\hangindent}. If \\{par\_shape\_ptr} is not null, it
points to a $(2n+1)$-word record in \\{mem}, where the \\{info} in the first
word contains the value of \|n, and the other $2n$ words contain the left
margins and line lengths for the first \|n lines of the paragraph; the
specifications for line \|n apply to all subsequent lines. If
$\\{par\_shape\_ptr}=\\{null}$, the shape of the paragraph depends on the value
of
$\|n=\\{hang\_after}$; if $\|n\G0$, hanging indentation takes place on lines $%
\|n+1$,
$\|n+2$, \dots, otherwise it takes place on lines 1, \dots, $\vert
n\vert$. When hanging indentation is active, the left margin is
\\{hang\_indent}, if $\\{hang\_indent}\G0$, else it is 0; the line length is
$\\{hsize}-\vert\\{hang\_indent}\vert$. The normal setting is
$\\{par\_shape\_ptr}=\\{null}$, $\\{hang\_after}=0$, and $\\{hang\_indent}=1$.
Note that if $\\{hang\_indent}=0$, the value of \\{hang\_after} is irrelevant.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{easy\_line}: \37\\{halfword};\C{line numbers $>\\{easy\_line}$ are
equivalent in break nodes}\6
\4\\{last\_special\_line}: \37\\{halfword};\C{line numbers $>\\{last\_special%
\_line}$ all have 	the same width}\6
\4\\{first\_width}: \37\\{scaled};\C{the width of all lines $\L\\{last\_special%
\_line}$, if 	no \.{\\parshape} has been specified}\6
\4\\{second\_width}: \37\\{scaled};\C{the width of all lines $>\\{last\_special%
\_line}$}\6
\4\\{first\_indent}: \37\\{scaled};\C{left margin to go with \\{first\_width}}\6
\4\\{second\_indent}: \37\\{scaled};\C{left margin to go with \\{second%
\_width}}\par
\fi

\M848. We compute the values of \\{easy\_line} and the other local variables
relating
to line length when the \\{line\_break} procedure is initializing itself.

\Y\P$\4\X816:Get ready to start line breaking\X\mathrel{+}\S$\6
\&{if} $\\{par\_shape\_ptr}=\\{null}$ \1\&{then}\6
\&{if} $\\{hang\_indent}=0$ \1\&{then}\6
\&{begin} \37$\\{last\_special\_line}\K0$;\5
$\\{second\_width}\K\\{hsize}$;\5
$\\{second\_indent}\K0$;\6
\&{end}\6
\4\&{else} \X849:Set line length parameters in preparation for hanging
indentation\X\2\6
\4\&{else} \&{begin} \37$\\{last\_special\_line}\K\\{info}(\\{par\_shape%
\_ptr})-1$;\5
$\\{second\_width}\K\\{mem}[\\{par\_shape\_ptr}+2\ast(\\{last\_special%
\_line}+1)].\\{sc}$;\5
$\\{second\_indent}\K\\{mem}[\\{par\_shape\_ptr}+2\ast\\{last\_special%
\_line}+1].\\{sc}$;\6
\&{end};\2\6
\&{if} $\\{looseness}=0$ \1\&{then}\5
$\\{easy\_line}\K\\{last\_special\_line}$\6
\4\&{else} $\\{easy\_line}\K\\{max\_halfword}$\2\par
\fi

\M849. \P$\X849:Set line length parameters in preparation for hanging
indentation\X\S$\6
\&{begin} \37$\\{last\_special\_line}\K\\{abs}(\\{hang\_after})$;\6
\&{if} $\\{hang\_after}<0$ \1\&{then}\6
\&{begin} \37$\\{first\_width}\K\\{hsize}-\\{abs}(\\{hang\_indent})$;\6
\&{if} $\\{hang\_indent}\G0$ \1\&{then}\5
$\\{first\_indent}\K\\{hang\_indent}$\6
\4\&{else} $\\{first\_indent}\K0$;\2\6
$\\{second\_width}\K\\{hsize}$;\5
$\\{second\_indent}\K0$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{first\_width}\K\\{hsize}$;\5
$\\{first\_indent}\K0$;\5
$\\{second\_width}\K\\{hsize}-\\{abs}(\\{hang\_indent})$;\6
\&{if} $\\{hang\_indent}\G0$ \1\&{then}\5
$\\{second\_indent}\K\\{hang\_indent}$\6
\4\&{else} $\\{second\_indent}\K0$;\2\6
\&{end};\2\6
\&{end}\par
\U section~848.\fi

\M850. When we come to the following code, we have just encountered the first
active node~\|r whose \\{line\_number} field contains \|l. Thus we want to
compute the length of the $l\,$th line of the current paragraph. Furthermore
we want to set \\{old\_l} to the last number in the class of line numbers
equivalent to~\|l.

\Y\P$\4\X850:Compute the new line width\X\S$\6
\&{if} $\|l>\\{easy\_line}$ \1\&{then}\6
\&{begin} \37$\\{line\_width}\K\\{second\_width}$;\5
$\\{old\_l}\K\\{max\_halfword}-1$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{old\_l}\K\|l$;\6
\&{if} $\|l>\\{last\_special\_line}$ \1\&{then}\5
$\\{line\_width}\K\\{second\_width}$\6
\4\&{else} \&{if} $\\{par\_shape\_ptr}=\\{null}$ \1\&{then}\5
$\\{line\_width}\K\\{first\_width}$\6
\4\&{else} $\\{line\_width}\K\\{mem}[\\{par\_shape\_ptr}+2\ast\|l\,].\\{sc}$;\2%
\2\6
\&{end}\2\par
\U section~835.\fi

\M851. The remaining part of \\{try\_break} deals with the calculation of
demerits for a break from \|r to \\{cur\_p}.

The first thing to do is calculate the badness, \|b. This value will always
be between zero and $\\{inf\_bad}+1$; the latter value occurs only in the
case of lines from \|r to \\{cur\_p} that cannot shrink enough to fit the
necessary
width. In such cases, node \|r will be deactivated.
We also deactivate node~\|r when a break at~\\{cur\_p} is forced, since future
breaks must go through a forced break.

\Y\P$\4\X851:Consider the demerits for a line from \|r to \\{cur\_p};
deactivate node \|r if it should no longer be active; then \&{goto} %
\\{continue} if a line from \|r to \\{cur\_p} is infeasible, otherwise record a
new feasible break\X\S$\6
\&{begin} \37\&{stat} \37$\\{artificial\_badness}\K\\{false}$;\ \&{tats}\6
$\\{shortfall}\K\\{line\_width}-\\{cur\_active\_width}[1]$;\C{we're this much
too short}\6
\&{if} $\\{shortfall}>0$ \1\&{then}\5
\X852:Set the value of \|b to the badness for stretching the line, and compute
the corresponding \\{fit\_class}\X\6
\4\&{else} \X853:Set the value of \|b to the badness for shrinking the line,
and compute the corresponding \\{fit\_class}\X;\2\6
\&{if} $(\|b>\\{inf\_bad})\V(\\{pi}=\\{eject\_penalty})$ \1\&{then}\5
\X854:Prepare to deactivate node~\|r, and \&{goto} \\{deactivate} unless there
is a reason to consider lines of text from \|r to \\{cur\_p}\X\6
\4\&{else} \&{begin} \37$\\{prev\_r}\K\|r$;\6
\&{if} $\|b>\\{threshold}$ \1\&{then}\5
\&{goto} \37\\{continue};\2\6
$\\{node\_r\_stays\_active}\K\\{true}$;\6
\&{end};\2\6
\X855:Record a new feasible break\X;\6
\&{if} $\\{node\_r\_stays\_active}$ \1\&{then}\5
\&{goto} \37\\{continue};\C{\\{prev\_r} has been set to \|r}\2\6
\4\\{deactivate}: \37\X860:Deactivate node \|r\X;\6
\&{end}\par
\U section~829.\fi

\M852. When a line must stretch, the available stretchability appears in the
subarray $\\{cur\_active\_width}[2\to5]$, in units of points, fil, fill, and
filll.

The present section is part of \TeX's inner loop, and it is most often
performed
when the badness is infinite; therefore it is worth while to make a quick
test for large width excess and small stretchability, before calling the
\\{badness} subroutine.

\Y\P$\4\X852:Set the value of \|b to the badness for stretching the line, and
compute the corresponding \\{fit\_class}\X\S$\6
\&{if} $(\\{cur\_active\_width}[3]\I0)\V(\\{cur\_active\_width}[4]\I0)\V\30(%
\\{cur\_active\_width}[5]\I0)$ \1\&{then}\6
\&{begin} \37$\|b\K0$;\5
$\\{fit\_class}\K\\{decent\_fit}$;\C{infinite stretch}\6
\&{end}\6
\4\&{else} \&{begin} \37\&{if} $\\{shortfall}>7230584$ \1\&{then}\6
\&{if} $\\{cur\_active\_width}[2]<1663497$ \1\&{then}\6
\&{begin} \37$\|b\K\\{inf\_bad}$;\5
$\\{fit\_class}\K\\{very\_loose\_fit}$;\5
\&{goto} \37\\{done1};\6
\&{end};\2\2\6
$\|b\K\\{badness}(\\{shortfall},\39\\{cur\_active\_width}[2])$;\6
\&{if} $\|b>12$ \1\&{then}\6
\&{if} $\|b>99$ \1\&{then}\5
$\\{fit\_class}\K\\{very\_loose\_fit}$\6
\4\&{else} $\\{fit\_class}\K\\{loose\_fit}$\2\6
\4\&{else} $\\{fit\_class}\K\\{decent\_fit}$;\2\6
\4\\{done1}: \37\&{end}\2\par
\U section~851.\fi

\M853. Shrinkability is never infinite in a paragraph;
we can shrink the line from \|r to \\{cur\_p} by at most $\\{cur\_active%
\_width}[6]$.

\Y\P$\4\X853:Set the value of \|b to the badness for shrinking the line, and
compute the corresponding \\{fit\_class}\X\S$\6
\&{begin} \37\&{if} $-\\{shortfall}>\\{cur\_active\_width}[6]$ \1\&{then}\5
$\|b\K\\{inf\_bad}+1$\6
\4\&{else} $\|b\K\\{badness}(-\\{shortfall},\39\\{cur\_active\_width}[6])$;\2\6
\&{if} $\|b>12$ \1\&{then}\5
$\\{fit\_class}\K\\{tight\_fit}$\ \&{else} $\\{fit\_class}\K\\{decent\_fit}$;\2%
\6
\&{end}\par
\U section~851.\fi

\M854. During the second pass, we dare not lose all active nodes, lest we lose
touch with the line breaks already found. The code shown here makes sure
that such a catastrophe does not happen, by permitting overfull boxes as
a last resort. This particular part of \TeX\ was a source of several subtle
bugs before the correct program logic was finally discovered; readers
who seek to ``improve'' \TeX\ should therefore think thrice before daring
to make any changes here.

\Y\P$\4\X854:Prepare to deactivate node~\|r, and \&{goto} \\{deactivate} unless
there is a reason to consider lines of text from \|r to \\{cur\_p}\X\S$\6
\&{begin} \37\&{if} $\\{second\_pass}\W(\\{minimum\_demerits}=\\{awful\_bad})\W%
\30(\\{link}(\|r)=\\{last\_active})\W(\\{prev\_r}=\\{active})$ \1\&{then}\6
\&{begin} \37$\|b\K0$;\C{set badness zero, this break is forced}\6
\&{stat} \37$\\{artificial\_badness}\K\\{true}$;\ \&{tats}\6
\&{end}\6
\4\&{else} \&{if} $\|b>\\{threshold}$ \1\&{then}\5
\&{goto} \37\\{deactivate};\2\2\6
$\\{node\_r\_stays\_active}\K\\{false}$;\6
\&{end}\par
\U section~851.\fi

\M855. When we get to this part of the code, the line from \|r to \\{cur\_p} is
feasible, its badness is~\|b, and its fitness classification is \\{fit\_class}.
We don't want to make an active node for this break yet, but we will
compute the total demerits and record them in the \\{minimal\_demerits} array,
if such a break is the current champion among all ways to get to \\{cur\_p}
in a given line-number class and fitness class.

\Y\P$\4\X855:Record a new feasible break\X\S$\6
\X859:Compute the demerits, \|d, from \|r to \\{cur\_p}\X;\6
\&{stat} \37\&{if} $\\{tracing\_paragraphs}>0$ \1\&{then}\5
\X856:Print a symbolic description of this feasible break\X;\2\6
\&{tats}\6
$\|d\K\|d+\\{total\_demerits}(\|r)$;\C{this is the minimum total demerits 	from
the beginning to \\{cur\_p} via \|r}\6
\&{if} $\|d\L\\{minimal\_demerits}[\\{fit\_class}]$ \1\&{then}\6
\&{begin} \37$\\{minimal\_demerits}[\\{fit\_class}]\K\|d$;\5
$\\{best\_place}[\\{fit\_class}]\K\\{break\_node}(\|r)$;\5
$\\{best\_pl\_line}[\\{fit\_class}]\K\|l$;\6
\&{if} $\|d<\\{minimum\_demerits}$ \1\&{then}\5
$\\{minimum\_demerits}\K\|d$;\2\6
\&{end}\2\par
\U section~851.\fi

\M856. \P$\X856:Print a symbolic description of this feasible break\X\S$\6
\&{begin} \37\&{if} $\\{printed\_node}\I\\{cur\_p}$ \1\&{then}\5
\X857:Print the list between \\{printed\_node} and \\{cur\_p}, then set $%
\\{printed\_node}\K\\{cur\_p}$\X;\2\6
$\\{print\_nl}(\.{"@"})$;\6
\&{if} $\\{cur\_p}=\\{null}$ \1\&{then}\5
$\\{print\_esc}(\.{"par"})$\6
\4\&{else} \&{if} $\\{type}(\\{cur\_p})\I\\{glue\_node}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{type}(\\{cur\_p})=\\{penalty\_node}$ \1\&{then}\5
$\\{print\_esc}(\.{"penalty"})$\6
\4\&{else} \&{if} $\\{type}(\\{cur\_p})=\\{disc\_node}$ \1\&{then}\5
$\\{print\_esc}(\.{"discretionary"})$\6
\4\&{else} \&{if} $\\{type}(\\{cur\_p})=\\{kern\_node}$ \1\&{then}\5
$\\{print\_esc}(\.{"kern"})$\6
\4\&{else} $\\{print\_esc}(\.{"math"})$;\2\2\2\6
\&{end};\2\2\6
$\\{print}(\.{"\ via\ @@"})$;\6
\&{if} $\\{break\_node}(\|r)=\\{null}$ \1\&{then}\5
$\\{print\_char}(\.{"0"})$\6
\4\&{else} $\\{print\_int}(\\{serial}(\\{break\_node}(\|r)))$;\2\6
$\\{print}(\.{"\ b="})$;\6
\&{if} $\\{artificial\_badness}$ \1\&{then}\5
$\\{print\_char}(\.{"*"})$\ \&{else} $\\{print\_int}(\|b)$;\2\6
$\\{print}(\.{"\ p="})$;\5
$\\{print\_int}(\\{pi})$;\5
$\\{print}(\.{"\ d="})$;\5
$\\{print\_int}(\|d)$;\6
\&{end}\par
\U section~855.\fi

\M857. \P$\X857:Print the list between \\{printed\_node} and \\{cur\_p}, then
set $\\{printed\_node}\K\\{cur\_p}$\X\S$\6
\&{begin} \37$\\{print\_nl}(\.{""})$;\6
\&{if} $\\{cur\_p}=\\{null}$ \1\&{then}\5
$\\{short\_display}(\\{link}(\\{printed\_node}))$\6
\4\&{else} \&{begin} \37$\\{save\_link}\K\\{link}(\\{cur\_p})$;\5
$\\{link}(\\{cur\_p})\K\\{null}$;\5
$\\{print\_nl}(\.{""})$;\5
$\\{short\_display}(\\{link}(\\{printed\_node}))$;\5
$\\{link}(\\{cur\_p})\K\\{save\_link}$;\6
\&{end};\2\6
$\\{printed\_node}\K\\{cur\_p}$;\6
\&{end}\par
\U section~856.\fi

\M858. When the data for a discretionary break is being displayed, we will have
printed the \\{pre\_break} and \\{post\_break} lists; we want to skip over the
third list, so that the discretionary data will not appear twice.  The
following code is performed at the very end of \\{try\_break}.

\Y\P$\4\X858:Update the value of \\{printed\_node} for symbolic displays\X\S$\6
\&{if} $\\{cur\_p}=\\{printed\_node}$ \1\&{then}\6
\&{if} $\\{cur\_p}\I\\{null}$ \1\&{then}\6
\&{if} $\\{type}(\\{cur\_p})=\\{disc\_node}$ \1\&{then}\6
\&{begin} \37$\|t\K\\{replace\_count}(\\{cur\_p})$;\6
\&{while} $\|t>0$ \1\&{do}\6
\&{begin} \37$\\{decr}(\|t)$;\5
$\\{printed\_node}\K\\{link}(\\{printed\_node})$;\6
\&{end};\2\6
\&{end}\2\2\2\par
\U section~829.\fi

\M859. \P$\X859:Compute the demerits, \|d, from \|r to \\{cur\_p}\X\S$\6
$\|d\K\\{line\_penalty}+\|b$;\5
$\|d\K\|d\ast\|d$;\6
\&{if} $\\{pi}\I0$ \1\&{then}\6
\&{if} $\\{pi}>0$ \1\&{then}\5
$\|d\K\|d+\\{pi}\ast\\{pi}$\6
\4\&{else} \&{if} $\\{pi}>\\{eject\_penalty}$ \1\&{then}\5
$\|d\K\|d-\\{pi}\ast\\{pi}$;\2\2\2\6
\&{if} $(\\{break\_type}=\\{hyphenated})\W(\\{type}(\|r)=\\{hyphenated})$ \1%
\&{then}\6
\&{if} $\\{cur\_p}\I\\{null}$ \1\&{then}\5
$\|d\K\|d+\\{double\_hyphen\_demerits}$\6
\4\&{else} $\|d\K\|d+\\{final\_hyphen\_demerits}$;\2\2\6
\&{if} $\\{abs}(\\{fit\_class}-\\{fitness}(\|r))>1$ \1\&{then}\5
$\|d\K\|d+\\{adj\_demerits}$\2\par
\U section~855.\fi

\M860. When an active node disappears, we must delete an adjacent delta node if
the
active node was at the beginning or the end of the active list, or if it
was surrounded by delta nodes. We also must preserve the property that
\\{cur\_active\_width} represents the length of material from $\\{link}(\\{prev%
\_r})$
to~\\{cur\_p}.

\Y\P\D \37$\\{combine\_two\_deltas}(\#)\S\30\\{mem}[\\{prev\_r}+\#].\\{sc}\K%
\\{mem}[\\{prev\_r}+\#].\\{sc}+\\{mem}[\|r+\#].\\{sc}$\par
\P\D \37$\\{downdate\_width}(\#)\S\30\\{cur\_active\_width}[\#]\K\\{cur\_active%
\_width}[\#]-\\{mem}[\\{prev\_r}+\#].\\{sc}$\par
\Y\P$\4\X860:Deactivate node \|r\X\S$\6
$\\{link}(\\{prev\_r})\K\\{link}(\|r)$;\5
$\\{free\_node}(\|r,\39\\{active\_node\_size})$;\6
\&{if} $\\{prev\_r}=\\{active}$ \1\&{then}\5
\X861:Update the active widths, since the first active node has been deleted\X\6
\4\&{else} \&{if} $\\{type}(\\{prev\_r})=\\{delta\_node}$ \1\&{then}\6
\&{begin} \37$\|r\K\\{link}(\\{prev\_r})$;\6
\&{if} $\|r=\\{last\_active}$ \1\&{then}\6
\&{begin} \37$\\{do\_all\_six}(\\{downdate\_width})$;\5
$\\{link}(\\{prev\_prev\_r})\K\\{last\_active}$;\5
$\\{free\_node}(\\{prev\_r},\39\\{delta\_node\_size})$;\5
$\\{prev\_r}\K\\{prev\_prev\_r}$;\6
\&{end}\6
\4\&{else} \&{if} $\\{type}(\|r)=\\{delta\_node}$ \1\&{then}\6
\&{begin} \37$\\{do\_all\_six}(\\{update\_width})$;\5
$\\{do\_all\_six}(\\{combine\_two\_deltas})$;\5
$\\{link}(\\{prev\_r})\K\\{link}(\|r)$;\5
$\\{free\_node}(\|r,\39\\{delta\_node\_size})$;\6
\&{end};\2\2\6
\&{end}\2\2\par
\U section~851.\fi

\M861. The following code uses the fact that $\\{type}(\\{last\_active})\I%
\\{delta\_node}$. If the
active list has just become empty, we do not need to update the
\\{active\_width} array, since it will be initialized when an active
node is next inserted.

\Y\P\D \37$\\{update\_active}(\#)\S\\{active\_width}[\#]\K\\{active\_width}[%
\#]+\\{mem}[\|r+\#].\\{sc}$\par
\Y\P$\4\X861:Update the active widths, since the first active node has been
deleted\X\S$\6
\&{begin} \37$\|r\K\\{link}(\\{active})$;\6
\&{if} $\\{type}(\|r)=\\{delta\_node}$ \1\&{then}\6
\&{begin} \37$\\{do\_all\_six}(\\{update\_active})$;\5
$\\{do\_all\_six}(\\{copy\_to\_cur\_active})$;\5
$\\{link}(\\{active})\K\\{link}(\|r)$;\5
$\\{free\_node}(\|r,\39\\{delta\_node\_size})$;\6
\&{end};\2\6
\&{end}\par
\U section~860.\fi

\N862.  \[39] Breaking paragraphs into lines, continued.
So far we have gotten a little way into the \\{line\_break} routine, having
covered its important \\{try\_break} subroutine. Now let's consider the
rest of the process.

The main loop of \\{line\_break} traverses the hlist of the given paragraph,
starting at $\\{link}(\\{temp\_head})$, and calls \\{try\_break} at each legal
breakpoint. A variable called \\{auto\_breaking} is set to true except
within math formulas, since glue nodes are not legal breakpoints when
they appear in formulas.

The current node of interest in the hlist is pointed to by \\{cur\_p}. Another
variable, \\{prev\_p}, is usually one step behind \\{cur\_p}, but the real
meaning of \\{prev\_p} is this: If $\\{type}(\\{cur\_p})=\\{glue\_node}$ then %
\\{cur\_p} is a legal
breakpoint if and only if \\{auto\_breaking} is true and \\{prev\_p} does not
point to a glue node, penalty node, kern node, or math node.

The following declarations provide for a few other local variables that are
used in special calculations.

\Y\P$\4\X862:Local variables for line breaking\X\S$\6
\4\\{auto\_breaking}: \37\\{boolean};\C{is node \\{cur\_p} outside a formula?}\6
\4\\{prev\_p}: \37\\{pointer};\C{helps to determine when glue nodes are
breakpoints}\6
\4$\|q,\39\|r,\39\|s$: \37\\{pointer};\C{miscellaneous nodes of temporary
interest}\6
\4\|f: \37\\{internal\_font\_number};\C{used when calculating character widths}%
\par
\A section~893.
\U section~815.\fi

\M863. The `\ignorespaces \~ \&{loop}\unskip' in the following code is
performed at most
twice per call of \\{line\_break}, since it is actually a pass over the
entire paragraph.

\Y\P$\4\X863:Find optimal breakpoints\X\S$\6
$\\{threshold}\K\\{pretolerance}$;\6
\&{if} $\\{threshold}\G0$ \1\&{then}\6
\&{begin} \37\&{stat} \37\&{if} $\\{tracing\_paragraphs}>0$ \1\&{then}\6
\&{begin} \37\\{begin\_diagnostic};\5
$\\{print\_nl}(\.{"@firstpass"})$;\ \&{end};\2\ \&{tats}\6
$\\{second\_pass}\K\\{false}$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{threshold}\K\\{tolerance}$;\5
$\\{second\_pass}\K\\{true}$;\6
\&{stat} \37\&{if} $\\{tracing\_paragraphs}>0$ \1\&{then}\5
\\{begin\_diagnostic};\ \2\6
\&{tats}\6
\&{end};\2\6
\~ \1\&{loop}\ \&{begin} \37\X864:Create an active breakpoint representing the
beginning of the paragraph\X;\6
$\\{cur\_p}\K\\{link}(\\{temp\_head})$;\5
$\\{auto\_breaking}\K\\{true}$;\6
$\\{prev\_p}\K\\{cur\_p}$;\C{glue at beginning is not a legal breakpoint}\6
\&{while} $(\\{cur\_p}\I\\{null})\W(\\{link}(\\{active})\I\\{last\_active})$ \1%
\&{do}\5
\X866:Call \\{try\_break} if \\{cur\_p} is a legal breakpoint; on the second
pass, also try to hyphenate the next word, if \\{cur\_p} is a glue node; then
advance \\{cur\_p} to the next node of the paragraph that could possibly be a
legal breakpoint\X;\2\6
\&{if} $\\{cur\_p}=\\{null}$ \1\&{then}\5
\X873:Try the final line break at the end of the paragraph, and \&{goto} %
\\{done} if the desired breakpoints have been found\X;\2\6
\X865:Clean up the memory by removing the break nodes\X;\6
\&{stat} \37\&{if} $\\{tracing\_paragraphs}>0$ \1\&{then}\5
$\\{print\_nl}(\.{"@secondpass"})$;\2\ \&{tats}\6
$\\{threshold}\K\\{tolerance}$;\5
$\\{second\_pass}\K\\{true}$;\C{if at first you don't 		succeed, \dots}\6
\&{end};\2\6
\4\\{done}: \37\&{stat} \37\&{if} $\\{tracing\_paragraphs}>0$ \1\&{then}\5
$\\{end\_diagnostic}(\\{true})$;\2\ \&{tats}\par
\U section~815.\fi

\M864. The active node that represents the starting point does not need a
corresponding passive node.

\Y\P\D \37$\\{store\_background}(\#)\S\\{active\_width}[\#]\K\\{background}[%
\#]$\par
\Y\P$\4\X864:Create an active breakpoint representing the beginning of the
paragraph\X\S$\6
$\|q\K\\{get\_node}(\\{active\_node\_size})$;\5
$\\{type}(\|q)\K\\{unhyphenated}$;\5
$\\{fitness}(\|q)\K\\{decent\_fit}$;\5
$\\{link}(\|q)\K\\{last\_active}$;\5
$\\{break\_node}(\|q)\K\\{null}$;\5
$\\{line\_number}(\|q)\K\\{prev\_graf}+1$;\5
$\\{total\_demerits}(\|q)\K0$;\5
$\\{link}(\\{active})\K\|q$;\5
$\\{do\_all\_six}(\\{store\_background})$;\6
$\\{passive}\K\\{null}$;\5
$\\{printed\_node}\K\\{temp\_head}$;\5
$\\{pass\_number}\K0$;\5
$\\{font\_in\_short\_display}\K\\{null\_font}$\par
\U section~863.\fi

\M865. \P$\X865:Clean up the memory by removing the break nodes\X\S$\6
$\|q\K\\{link}(\\{active})$;\6
\&{while} $\|q\I\\{last\_active}$ \1\&{do}\6
\&{begin} \37$\\{cur\_p}\K\\{link}(\|q)$;\6
\&{if} $\\{type}(\|q)=\\{delta\_node}$ \1\&{then}\5
$\\{free\_node}(\|q,\39\\{delta\_node\_size})$\6
\4\&{else} $\\{free\_node}(\|q,\39\\{active\_node\_size})$;\2\6
$\|q\K\\{cur\_p}$;\6
\&{end};\2\6
$\|q\K\\{passive}$;\6
\&{while} $\|q\I\\{null}$ \1\&{do}\6
\&{begin} \37$\\{cur\_p}\K\\{link}(\|q)$;\5
$\\{free\_node}(\|q,\39\\{passive\_node\_size})$;\5
$\|q\K\\{cur\_p}$;\6
\&{end}\2\par
\U sections~815 and~863.\fi

\M866. Here is the main switch in the \\{line\_break} routine, where legal
breaks
are determined. As we move through the hlist, we need to keep the \\{active%
\_width}
array up to date, so that the badness of individual lines is readily calculated
by \\{try\_break}. It is convenient to use the short name \\{act\_width} for
the component of active width that represents real width as opposed to glue.

\Y\P\D \37$\\{act\_width}\S\\{active\_width}[1]$\C{length from first active
node to current node}\par
\P\D \37$\\{kern\_break}\S$\1\6
\&{begin} \37\hbox{}\6
\&{if} $\R\\{is\_char\_node}(\\{link}(\\{cur\_p}))\W\\{auto\_breaking}$ \1%
\&{then}\6
\&{if} $\\{type}(\\{link}(\\{cur\_p}))=\\{glue\_node}$ \1\&{then}\5
$\\{try\_break}(0,\39\\{unhyphenated})$;\2\2\6
$\\{act\_width}\K\\{act\_width}+\\{width}(\\{cur\_p})$;\6
\&{end}\2\par
\Y\P$\4\X866:Call \\{try\_break} if \\{cur\_p} is a legal breakpoint; on the
second pass, also try to hyphenate the next word, if \\{cur\_p} is a glue node;
then advance \\{cur\_p} to the next node of the paragraph that could possibly
be a legal breakpoint\X\S$\6
\&{begin} \37\&{if} $\\{is\_char\_node}(\\{cur\_p})$ \1\&{then}\5
\X867\*:Advance \(c)\\{cur\_p} to the node following the present string of
characters\X;\2\6
\&{case} $\\{type}(\\{cur\_p})$ \1\&{of}\6
\4$\\{hlist\_node},\39\\{vlist\_node},\39\\{rule\_node}$: \37$\\{act\_width}\K%
\\{act\_width}+\\{width}(\\{cur\_p})$;\6
\4\\{whatsit\_node}: \37\X1362:Advance \(p)past a whatsit node in the \\{line%
\_break} loop\X;\6
\4\\{glue\_node}: \37\&{begin} \37\X868:If node \\{cur\_p} is a legal
breakpoint, call \\{try\_break}\X;\6
\X869:Update the active widths by including the glue in $\\{glue\_ptr}(\\{cur%
\_p})$\X;\6
\&{if} $\\{second\_pass}\W\\{auto\_breaking}$ \1\&{then}\5
\X894:Try to hyphenate the following word\X;\2\6
\&{end};\6
\4\\{kern\_node}: \37\\{kern\_break};\6
\4\\{ligature\_node}: \37\&{begin} \37$\|f\K\\{font}(\\{lig\_char}(\\{cur%
\_p}))$;\5
$\\{act\_width}\K\\{act\_width}+\\{char\_width}(\|f)(\\{char\_info}(\|f)(%
\\{character}(\\{lig\_char}(\\{cur\_p}))))$;\6
\&{end};\6
\4\\{disc\_node}: \37\X870:Try to break after a discretionary fragment\X;\6
\4\\{math\_node}: \37\&{begin} \37$\\{auto\_breaking}\K(\\{subtype}(\\{cur%
\_p})=\\{after})$;\5
\\{kern\_break};\6
\&{end};\6
\4\\{penalty\_node}: \37$\\{try\_break}(\\{penalty}(\\{cur\_p}),\39%
\\{unhyphenated})$;\6
\4$\\{mark\_node},\39\\{ins\_node},\39\\{adjust\_node}$: \37\\{do\_nothing};\6
\4\&{othercases} \37$\\{confusion}(\.{"paragraph"})$\2\6
\&{endcases};\6
$\\{prev\_p}\K\\{cur\_p}$;\5
$\\{cur\_p}\K\\{link}(\\{cur\_p})$;\6
\&{end}\par
\U section~863.\fi

\M867\*. The code that passes over the characters of words in a paragraph is
part of \TeX's inner loop, so it has been streamlined for speed. We use
the fact that `\.{\\parfillskip}' glue appears at the end of each paragraph;
it is therefore unnecessary to check if $\\{link}(\\{cur\_p})=\\{null}$ when %
\\{cur\_p} is a
character node.

\Y\P$\4\X867\*:Advance \(c)\\{cur\_p} to the node following the present string
of characters\X\S$\6
\&{begin} \37$\\{prev\_p}\K\\{cur\_p}$;\6
\1\&{repeat} \37$\\{bypass\_xchar}(\\{cur\_p})$;\5
$\|f\K\\{font}(\\{cur\_p})$;\5
$\\{act\_width}\K\\{act\_width}+\\{char\_width}(\|f)(\\{char\_info}(\|f)(%
\\{character}(\\{cur\_p})))$;\5
$\\{cur\_p}\K\\{link}(\\{cur\_p})$;\6
\4\&{until}\5
$\R\\{is\_char\_node}(\\{cur\_p})$;\2\6
\&{end}\par
\U section~866.\fi

\M868. When node \\{cur\_p} is a glue node, we look at \\{prev\_p} to see
whether or not
a breakpoint is legal at \\{cur\_p}, as explained above.

\Y\P$\4\X868:If node \\{cur\_p} is a legal breakpoint, call \\{try\_break}\X\S$%
\6
\&{if} $\\{auto\_breaking}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{is\_char\_node}(\\{prev\_p})$ \1\&{then}\5
$\\{try\_break}(0,\39\\{unhyphenated})$\6
\4\&{else} \&{if} $\\{precedes\_break}(\\{prev\_p})$ \1\&{then}\5
$\\{try\_break}(0,\39\\{unhyphenated})$;\2\2\6
\&{end}\2\par
\U section~866.\fi

\M869. \P$\X869:Update the active widths by including the glue in $\\{glue%
\_ptr}(\\{cur\_p})$\X\S$\6
\&{begin} \37$\\{check\_shrinkage}(\\{glue\_ptr}(\\{cur\_p}))$;\5
$\|q\K\\{glue\_ptr}(\\{cur\_p})$;\5
$\\{act\_width}\K\\{act\_width}+\\{width}(\|q)$;\5
$\30\\{active\_width}[2+\\{stretch\_order}(\|q)]\K\30\\{active\_width}[2+%
\\{stretch\_order}(\|q)]+\\{stretch}(\|q)$;\6
$\\{active\_width}[6]\K\\{active\_width}[6]+\\{shrink}(\|q)$;\6
\&{end}\par
\U section~866.\fi

\M870. The following code knows that discretionary texts contain
only character nodes, kern nodes, box nodes, rule nodes, and ligature nodes.

\Y\P$\4\X870:Try to break after a discretionary fragment\X\S$\6
\&{begin} \37$\|s\K\\{pre\_break}(\\{cur\_p})$;\5
$\\{disc\_width}\K0$;\6
\&{if} $\|s=\\{null}$ \1\&{then}\5
$\\{try\_break}(\\{ex\_hyphen\_penalty},\39\\{hyphenated})$\6
\4\&{else} \&{begin} \37\1\&{repeat} \37\X871\*:Add the width of node \|s to %
\\{disc\_width}\X;\6
$\|s\K\\{link}(\|s)$;\6
\4\&{until}\5
$\|s=\\{null}$;\2\6
$\\{act\_width}\K\\{act\_width}+\\{disc\_width}$;\5
$\\{try\_break}(\\{hyphen\_penalty},\39\\{hyphenated})$;\5
$\\{act\_width}\K\\{act\_width}-\\{disc\_width}$;\6
\&{end};\2\6
\&{end}\par
\U section~866.\fi

\M871\*. \P$\X871\*:Add the width of node \|s to \\{disc\_width}\X\S$\6
\&{if} $\\{is\_char\_node}(\|s)$ \1\&{then}\6
\&{begin} \37$\\{bypass\_xchar}(\|s)$;\5
$\|f\K\\{font}(\|s)$;\5
$\\{disc\_width}\K\\{disc\_width}+\\{char\_width}(\|f)(\\{char\_info}(\|f)(%
\\{character}(\|s)))$;\6
\&{end}\6
\4\&{else} \&{case} $\\{type}(\|s)$ \1\&{of}\6
\4\\{ligature\_node}: \37\&{begin} \37$\|f\K\\{font}(\\{lig\_char}(\|s))$;\5
$\\{disc\_width}\K\\{disc\_width}+\\{char\_width}(\|f)(\\{char\_info}(\|f)(%
\\{character}(\\{lig\_char}(\|s))))$;\6
\&{end};\6
\4$\\{hlist\_node},\39\\{vlist\_node},\39\\{rule\_node},\39\\{kern\_node}$: %
\37$\\{disc\_width}\K\\{disc\_width}+\\{width}(\|s)$;\6
\4\&{othercases} \37$\\{confusion}(\.{"disc3"})$\2\6
\&{endcases}\2\par
\U section~870.\fi

\M872. The forced line break at the paragraph's end will reduce the list of
breakpoints so that all active nodes represent breaks at $\\{cur\_p}=\\{null}$.
On the first pass, we insist on finding an active node that has the
correct ``looseness.'' On the second pass, there will be at least one active
node, and we will match the desired looseness as well as we can.

The global variable \\{best\_bet} will be set to the active node for the best
way to break the paragraph, and a few other variables are used to
help determine what is best.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{best\_bet}: \37\\{pointer};\C{use this passive node and its predecessors}\6
\4\\{fewest\_demerits}: \37\\{integer};\C{the demerits associated with \\{best%
\_bet}}\6
\4\\{best\_line}: \37\\{halfword};\C{line number following the last line of the
new paragraph}\6
\4\\{actual\_looseness}: \37\\{integer};\C{the difference between $\\{line%
\_number}(\\{best\_bet})$ 	and the optimum \\{best\_line}}\6
\4\\{line\_diff}: \37\\{integer};\C{the difference between the current line
number and 	the optimum \\{best\_line}}\par
\fi

\M873. \P$\X873:Try the final line break at the end of the paragraph, and %
\&{goto} \\{done} if the desired breakpoints have been found\X\S$\6
\&{begin} \37$\\{try\_break}(\\{eject\_penalty},\39\\{hyphenated})$;\6
\&{if} $\\{link}(\\{active})\I\\{last\_active}$ \1\&{then}\6
\&{begin} \37\X874:Find an active node with fewest demerits\X;\6
\&{if} $\\{looseness}=0$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
\X875:Find the best active node for the desired looseness\X;\6
\&{if} $(\\{actual\_looseness}=\\{looseness})\V\\{second\_pass}$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
\&{end};\2\6
\&{end}\par
\U section~863.\fi

\M874. \P$\X874:Find an active node with fewest demerits\X\S$\6
$\|r\K\\{link}(\\{active})$;\5
$\\{fewest\_demerits}\K\\{awful\_bad}$;\6
\1\&{repeat} \37\&{if} $\\{type}(\|r)\I\\{delta\_node}$ \1\&{then}\6
\&{if} $\\{total\_demerits}(\|r)<\\{fewest\_demerits}$ \1\&{then}\6
\&{begin} \37$\\{fewest\_demerits}\K\\{total\_demerits}(\|r)$;\5
$\\{best\_bet}\K\|r$;\6
\&{end};\2\2\6
$\|r\K\\{link}(\|r)$;\6
\4\&{until}\5
$\|r=\\{last\_active}$;\2\6
$\\{best\_line}\K\\{line\_number}(\\{best\_bet})$\par
\U section~873.\fi

\M875. The adjustment for a desired looseness is a slightly more complicated
version of the loop just considered. Note that if a paragraph is broken
into segments by displayed equations, each segment will be subject to the
looseness calculation, independently of the other segments.

\Y\P$\4\X875:Find the best active node for the desired looseness\X\S$\6
\&{begin} \37$\|r\K\\{link}(\\{active})$;\5
$\\{actual\_looseness}\K0$;\6
\1\&{repeat} \37\&{if} $\\{type}(\|r)\I\\{delta\_node}$ \1\&{then}\6
\&{begin} \37$\\{line\_diff}\K\\{line\_number}(\|r)-\\{best\_line}$;\6
\&{if} $((\\{line\_diff}<\\{actual\_looseness})\W(\\{looseness}\L\\{line%
\_diff}))\V\30((\\{line\_diff}>\\{actual\_looseness})\W(\\{looseness}\G\\{line%
\_diff}))$ \1\&{then}\6
\&{begin} \37$\\{best\_bet}\K\|r$;\5
$\\{actual\_looseness}\K\\{line\_diff}$;\5
$\\{fewest\_demerits}\K\\{total\_demerits}(\|r)$;\6
\&{end}\6
\4\&{else} \&{if} $(\\{line\_diff}=\\{actual\_looseness})\W\30(\\{total%
\_demerits}(\|r)<\\{fewest\_demerits})$ \1\&{then}\6
\&{begin} \37$\\{best\_bet}\K\|r$;\5
$\\{fewest\_demerits}\K\\{total\_demerits}(\|r)$;\6
\&{end};\2\2\6
\&{end};\2\6
$\|r\K\\{link}(\|r)$;\6
\4\&{until}\5
$\|r=\\{last\_active}$;\2\6
$\\{best\_line}\K\\{line\_number}(\\{best\_bet})$;\6
\&{end}\par
\U section~873.\fi

\M876. Once the best sequence of breakpoints has been found, we call on the
procedure \\{post\_line\_break} to finish the remainder of the work.
(By introducing this subprocedure, we are able to keep \\{line\_break}
from getting extremely long.)

\Y\P$\4\X876:Break the paragraph at the chosen breakpoints, justify the
resulting lines to the correct widths, and append them to the current vertical
list\X\S$\6
$\\{post\_line\_break}(\\{final\_widow\_penalty})$\par
\U section~815.\fi

\M877. The total number of lines that will be set by \\{post\_line\_break}
is $\\{best\_line}-\\{prev\_graf}-1$. The last breakpoint is specified by
$\\{break\_node}(\\{best\_bet})$, and this passive node points to the other
breakpoints
via the \\{prev\_break} links. The finishing-up phase starts by linking the
relevant passive nodes in forward order, changing \\{prev\_break} to
\\{next\_break}. (The \\{next\_break} fields actually reside in the same memory
space as the \\{prev\_break} fields did, but we give them a new name because
of their new significance.) Then the lines are justified, one by one.

\Y\P\D \37$\\{next\_break}\S\\{prev\_break}$\C{new name for \\{prev\_break}
after links are reversed}\par
\Y\P$\4\X826:Declare subprocedures for \\{line\_break}\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{post\_line\_break}(\\{final\_widow\_penalty}:%
\\{integer})$;\6
\4\&{label} \37$\\{done},\39\\{done1}$;\6
\4\&{var} \37$\|q,\39\|r,\39\|s$: \37\\{pointer};\C{temporary registers for
list manipulation}\6
\\{disc\_break}: \37\\{boolean};\C{was the current break at a discretionary
node?}\6
\\{cur\_width}: \37\\{scaled};\C{width of line number \\{cur\_line}}\6
\\{cur\_indent}: \37\\{scaled};\C{left margin of line number \\{cur\_line}}\6
\|t: \37\\{quarterword};\C{used for replacement counts in discretionary nodes}\6
\\{pen}: \37\\{integer};\C{use when calculating penalties between lines}\6
\\{cur\_line}: \37\\{halfword};\C{the current line number being justified}\2\6
\&{begin} \37\X878:Reverse the links of the relevant passive nodes, setting %
\\{cur\_p} to the first breakpoint\X;\6
$\\{cur\_line}\K\\{prev\_graf}+1$;\6
\1\&{repeat} \37\X880:Justify the line ending at breakpoint \\{cur\_p}, and
append it to the current vertical list, together with associated penalties and
other insertions\X;\6
$\\{incr}(\\{cur\_line})$;\5
$\\{cur\_p}\K\\{next\_break}(\\{cur\_p})$;\6
\&{if} $\\{cur\_p}\I\\{null}$ \1\&{then}\5
\X879:Prune unwanted nodes at the beginning of the next line\X;\2\6
\4\&{until}\5
$\\{cur\_p}=\\{null}$;\2\6
\&{if} $(\\{cur\_line}\I\\{best\_line})\V(\\{link}(\\{temp\_head})\I\\{null})$ %
\1\&{then}\5
$\\{confusion}(\.{"line\ breaking"})$;\2\6
$\\{prev\_graf}\K\\{best\_line}-1$;\6
\&{end};\par
\fi

\M878. The job of reversing links in a list is conveniently regarded as the job
of taking items off one stack and putting them on another. In this case we
take them off a stack pointed to by \|q and having \\{prev\_break} fields;
we put them on a stack pointed to by \\{cur\_p} and having \\{next\_break}
fields.
Node \|r is the passive node being moved from stack to stack.

\Y\P$\4\X878:Reverse the links of the relevant passive nodes, setting \\{cur%
\_p} to the first breakpoint\X\S$\6
$\|q\K\\{break\_node}(\\{best\_bet})$;\5
$\\{cur\_p}\K\\{null}$;\6
\1\&{repeat} \37$\|r\K\|q$;\5
$\|q\K\\{prev\_break}(\|q)$;\5
$\\{next\_break}(\|r)\K\\{cur\_p}$;\5
$\\{cur\_p}\K\|r$;\6
\4\&{until}\5
$\|q=\\{null}$\2\par
\U section~877.\fi

\M879. Glue and penalty and kern and math nodes are deleted at the beginning of
a line, except in the unusual case that the node to be deleted is actually
one of the chosen breakpoints. The pruning done here is designed to match
the lookahead computation in \\{try\_break}, where the \\{break\_width} values
are computed for non-discretionary breakpoints.

\Y\P$\4\X879:Prune unwanted nodes at the beginning of the next line\X\S$\6
\&{begin} \37$\|r\K\\{temp\_head}$;\6
\~ \1\&{loop}\ \&{begin} \37$\|q\K\\{link}(\|r)$;\6
\&{if} $\|q=\\{cur\_break}(\\{cur\_p})$ \1\&{then}\5
\&{goto} \37\\{done1};\C{$\\{cur\_break}(\\{cur\_p})$ is the next breakpoint}\6
\C{now \|q cannot be \\{null}}\2\6
\&{if} $\\{is\_char\_node}(\|q)$ \1\&{then}\5
\&{goto} \37\\{done1};\2\6
\&{if} $\\{non\_discardable}(\|q)$ \1\&{then}\5
\&{goto} \37\\{done1};\2\6
\&{if} $\\{subtype}(\|q)=\\{acc\_kern}$ \1\&{then}\6
\&{if} $\\{type}(\|q)=\\{kern\_node}$ \1\&{then}\5
\&{goto} \37\\{done1};\2\2\6
$\|r\K\|q$;\C{now $\\{type}(\|q)=\\{glue\_node}$, \\{kern\_node}, \\{math%
\_node} or \\{penalty\_node}}\6
\&{end};\2\6
\4\\{done1}: \37\&{if} $\|r\I\\{temp\_head}$ \1\&{then}\6
\&{begin} \37$\\{link}(\|r)\K\\{null}$;\5
$\\{flush\_node\_list}(\\{link}(\\{temp\_head}))$;\5
$\\{link}(\\{temp\_head})\K\|q$;\6
\&{end};\2\6
\&{end}\par
\U section~877.\fi

\M880. The current line to be justified appears in a horizontal list starting
at $\\{link}(\\{temp\_head})$ and ending at $\\{cur\_break}(\\{cur\_p})$. If $%
\\{cur\_break}(\\{cur\_p})$ is
a glue node, we reset the glue to equal the \\{right\_skip} glue; otherwise
we append the \\{right\_skip} glue at the right. If $\\{cur\_break}(\\{cur%
\_p})$ is a
discretionary node, we modify the list so that the discretionary break
is compulsory, and we set \\{disc\_break} to \\{true}. We also append
the \\{left\_skip} glue at the left of the line, unless it is zero.

\Y\P$\4\X880:Justify the line ending at breakpoint \\{cur\_p}, and append it to
the current vertical list, together with associated penalties and other
insertions\X\S$\6
\X881:Modify the end of the line to reflect the nature of the break and to
include \.{\\rightskip}; also set the proper value of \\{disc\_break}\X;\6
\X887:Put the \(l)\.{\\leftskip} glue at the left and detach this line\X;\6
\X889:Call the packaging subroutine, setting \\{just\_box} to the justified box%
\X;\6
\X888:Append the new box to the current vertical list, followed by the list of
special nodes taken out of the box by the packager\X;\6
\X890:Append a penalty node, if a nonzero penalty is appropriate\X\par
\U section~877.\fi

\M881. At the end of the following code, \|q will point to the final node on
the
list about to be justified.

\Y\P$\4\X881:Modify the end of the line to reflect the nature of the break and
to include \.{\\rightskip}; also set the proper value of \\{disc\_break}\X\S$\6
$\|q\K\\{cur\_break}(\\{cur\_p})$;\5
$\\{disc\_break}\K\\{false}$;\6
\&{if} $\|q\I\\{null}$ \1\&{then}\C{\|q cannot be a \\{char\_node}}\6
\&{if} $\\{type}(\|q)=\\{glue\_node}$ \1\&{then}\6
\&{begin} \37$\\{delete\_glue\_ref}(\\{glue\_ptr}(\|q))$;\5
$\\{glue\_ptr}(\|q)\K\\{right\_skip}$;\5
$\\{subtype}(\|q)\K\\{right\_skip\_code}+1$;\5
$\\{add\_glue\_ref}(\\{right\_skip})$;\5
\&{goto} \37\\{done};\6
\&{end}\6
\4\&{else} \&{begin} \37\&{if} $\\{type}(\|q)=\\{disc\_node}$ \1\&{then}\5
\X882:Change discretionary to compulsory and set $\\{disc\_break}\K\\{true}$\X\6
\4\&{else} \&{if} $(\\{type}(\|q)=\\{math\_node})\V(\\{type}(\|q)=\\{kern%
\_node})$ \1\&{then}\5
$\\{width}(\|q)\K0$;\2\2\6
\&{end}\2\6
\4\&{else} \&{begin} \37$\|q\K\\{temp\_head}$;\6
\&{while} $\\{link}(\|q)\I\\{null}$ \1\&{do}\5
$\|q\K\\{link}(\|q)$;\2\6
\&{end};\2\6
\X886:Put the \(r)\.{\\rightskip} glue after node \|q\X;\6
\4\\{done}: \37\par
\U section~880.\fi

\M882. \P$\X882:Change discretionary to compulsory and set $\\{disc\_break}\K%
\\{true}$\X\S$\6
\&{begin} \37$\|t\K\\{replace\_count}(\|q)$;\5
\X883:Destroy the \|t nodes following \|q, but save the last one if it is a
necessary kern; make \|r point to the following node\X;\6
\&{if} $\\{post\_break}(\|q)\I\\{null}$ \1\&{then}\5
\X884:Transplant the post-break list\X;\2\6
\&{if} $\\{pre\_break}(\|q)\I\\{null}$ \1\&{then}\5
\X885:Transplant the pre-break list\X;\2\6
$\\{link}(\|q)\K\|r$;\5
$\\{disc\_break}\K\\{true}$;\6
\&{end}\par
\U section~881.\fi

\M883. A subtle bug that would perhaps never have been detected is avoided here
by preserving a kern node that just might equal $\\{cur\_break}(\\{next%
\_break}(\\{cur\_p}))$.

\Y\P$\4\X883:Destroy the \|t nodes following \|q, but save the last one if it
is a necessary kern; make \|r point to the following node\X\S$\6
\&{if} $\|t=0$ \1\&{then}\5
$\|r\K\\{link}(\|q)$\6
\4\&{else} \&{begin} \37$\|r\K\|q$;\6
\&{while} $\|t>1$ \1\&{do}\6
\&{begin} \37$\|r\K\\{link}(\|r)$;\5
$\\{decr}(\|t)$;\6
\&{end};\2\6
$\|s\K\\{link}(\|r)$;\6
\&{if} $\R\\{is\_char\_node}(\|s)$ \1\&{then}\6
\&{if} $\\{next\_break}(\\{cur\_p})\I\\{null}$ \1\&{then}\6
\&{if} $\\{cur\_break}(\\{next\_break}(\\{cur\_p}))=\|s$ \1\&{then}\5
$\|s\K\|r$;\2\2\2\6
$\|r\K\\{link}(\|s)$;\5
$\\{link}(\|s)\K\\{null}$;\5
$\\{flush\_node\_list}(\\{link}(\|q))$;\5
$\\{replace\_count}(\|q)\K0$;\6
\&{end}\2\par
\U section~882.\fi

\M884. We move the post-break list from inside node \|q to the main list by
re\-attaching it just before the present node \|r, then resetting \|r.

\Y\P$\4\X884:Transplant the post-break list\X\S$\6
\&{begin} \37$\|s\K\\{post\_break}(\|q)$;\6
\&{while} $\\{link}(\|s)\I\\{null}$ \1\&{do}\5
$\|s\K\\{link}(\|s)$;\2\6
$\\{link}(\|s)\K\|r$;\5
$\|r\K\\{post\_break}(\|q)$;\5
$\\{post\_break}(\|q)\K\\{null}$;\6
\&{end}\par
\U section~882.\fi

\M885. We move the pre-break list from inside node \|q to the main list by
re\-attaching it just after the present node \|q, then resetting \|q.

\Y\P$\4\X885:Transplant the pre-break list\X\S$\6
\&{begin} \37$\|s\K\\{pre\_break}(\|q)$;\5
$\\{link}(\|q)\K\|s$;\6
\&{while} $\\{link}(\|s)\I\\{null}$ \1\&{do}\5
$\|s\K\\{link}(\|s)$;\2\6
$\\{pre\_break}(\|q)\K\\{null}$;\5
$\|q\K\|s$;\6
\&{end}\par
\U section~882.\fi

\M886. \P$\X886:Put the \(r)\.{\\rightskip} glue after node \|q\X\S$\6
$\|r\K\\{new\_param\_glue}(\\{right\_skip\_code})$;\5
$\\{link}(\|r)\K\\{link}(\|q)$;\5
$\\{link}(\|q)\K\|r$;\5
$\|q\K\|r$\par
\U section~881.\fi

\M887. The following code begins with \|q at the end of the list to be
justified. It ends with \|q at the beginning of that list, and with
$\\{link}(\\{temp\_head})$ pointing to the remainder of the paragraph, if any.

\Y\P$\4\X887:Put the \(l)\.{\\leftskip} glue at the left and detach this line\X%
\S$\6
$\|r\K\\{link}(\|q)$;\5
$\\{link}(\|q)\K\\{null}$;\5
$\|q\K\\{link}(\\{temp\_head})$;\5
$\\{link}(\\{temp\_head})\K\|r$;\6
\&{if} $\\{left\_skip}\I\\{zero\_glue}$ \1\&{then}\6
\&{begin} \37$\|r\K\\{new\_param\_glue}(\\{left\_skip\_code})$;\5
$\\{link}(\|r)\K\|q$;\5
$\|q\K\|r$;\6
\&{end}\2\par
\U section~880.\fi

\M888. \P$\X888:Append the new box to the current vertical list, followed by
the list of special nodes taken out of the box by the packager\X\S$\6
$\\{append\_to\_vlist}(\\{just\_box})$;\6
\&{if} $\\{adjust\_head}\I\\{adjust\_tail}$ \1\&{then}\6
\&{begin} \37$\\{link}(\\{tail})\K\\{link}(\\{adjust\_head})$;\5
$\\{tail}\K\\{adjust\_tail}$;\6
\&{end};\2\6
$\\{adjust\_tail}\K\\{null}$\par
\U section~880.\fi

\M889. Now \|q points to the hlist that represents the current line of the
paragraph. We need to compute the appropriate line width, pack the
line into a box of this size, and shift the box by the appropriate
amount of indentation.

\Y\P$\4\X889:Call the packaging subroutine, setting \\{just\_box} to the
justified box\X\S$\6
\&{if} $\\{cur\_line}>\\{last\_special\_line}$ \1\&{then}\6
\&{begin} \37$\\{cur\_width}\K\\{second\_width}$;\5
$\\{cur\_indent}\K\\{second\_indent}$;\6
\&{end}\6
\4\&{else} \&{if} $\\{par\_shape\_ptr}=\\{null}$ \1\&{then}\6
\&{begin} \37$\\{cur\_width}\K\\{first\_width}$;\5
$\\{cur\_indent}\K\\{first\_indent}$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{cur\_width}\K\\{mem}[\\{par\_shape\_ptr}+2\ast%
\\{cur\_line}].\\{sc}$;\5
$\\{cur\_indent}\K\\{mem}[\\{par\_shape\_ptr}+2\ast\\{cur\_line}-1].\\{sc}$;\6
\&{end};\2\2\6
$\\{adjust\_tail}\K\\{adjust\_head}$;\5
$\\{just\_box}\K\\{hpack}(\|q,\39\\{cur\_width},\39\\{exactly})$;\5
$\\{shift\_amount}(\\{just\_box})\K\\{cur\_indent}$\par
\U section~880.\fi

\M890. Penalties between the lines of a paragraph come from club and widow
lines,
from the \\{inter\_line\_penalty} parameter, and from lines that end at
discretionary breaks.  Breaking between lines of a two-line paragraph gets
both club-line and widow-line penalties. The local variable \\{pen} will
be set to the sum of all relevant penalties for the current line, except
that the final line is never penalized.

\Y\P$\4\X890:Append a penalty node, if a nonzero penalty is appropriate\X\S$\6
\&{if} $\\{cur\_line}+1\I\\{best\_line}$ \1\&{then}\6
\&{begin} \37$\\{pen}\K\\{inter\_line\_penalty}$;\6
\&{if} $\\{cur\_line}=\\{prev\_graf}+1$ \1\&{then}\5
$\\{pen}\K\\{pen}+\\{club\_penalty}$;\2\6
\&{if} $\\{cur\_line}+2=\\{best\_line}$ \1\&{then}\5
$\\{pen}\K\\{pen}+\\{final\_widow\_penalty}$;\2\6
\&{if} $\\{disc\_break}$ \1\&{then}\5
$\\{pen}\K\\{pen}+\\{broken\_penalty}$;\2\6
\&{if} $\\{pen}\I0$ \1\&{then}\6
\&{begin} \37$\|r\K\\{new\_penalty}(\\{pen})$;\5
$\\{link}(\\{tail})\K\|r$;\5
$\\{tail}\K\|r$;\6
\&{end};\2\6
\&{end}\2\par
\U section~880.\fi

\N891.  \[40] Pre-hyphenation.
When the line-breaking routine is unable to find a feasible sequence of
breakpoints, it makes a second pass over the paragraph, attempting to
hyphenate the hyphenatable words. The goal of hyphenation is to insert
discretionary material into the paragraph so that there are more
potential places to break.

The general rules for hyphenation are somewhat complex and technical,
because we want to be able to hyphenate words that are preceded or
followed by punctuation marks, and because we want the rules to work
for languages other than English. We also must contend with the fact
that hyphens might radically alter the ligature and kerning structure
of a word.

A sequence of characters will be considered for hyphenation only if it
belongs to a ``potentially hyphenatable part'' of the current paragraph.
This is a sequence of nodes $p_0p_1\ldots p_m$ where $p_0$ is a glue node,
$p_1\ldots p_{m-1}$ are either character or ligature or whatsit or
implicit kern nodes, and $p_m$ is a glue or penalty or insertion or adjust
or mark or whatsit or explicit kern node.  (Therefore hyphenation is
disabled by boxes, math formulas, and discretionary nodes already inserted
by the user.) The ligature nodes among $p_1\ldots p_{m-1}$ are effectively
expanded into the original non-ligature characters; the kern nodes and
whatsits are ignored. Each character \|c is now classified as either a
nonletter (if $\|c\G128$ or $\\{lc\_code}(\|c)=0$), a lowercase letter (if
$\\{lc\_code}(\|c)=\|c$), or an uppercase letter (otherwise); an uppercase
letter
is treated as if it were $\\{lc\_code}(\|c)$ for purposes of hyphenation. The
characters generated by $p_1\ldots p_{m-1}$ may begin with nonletters; let
$c_1$ be the first letter that is not in the middle of a ligature. Whatsit
nodes preceding $c_1$ are ignored; a whatsit found after $c_1$ will be the
terminating node $p_m$. All characters that do not have the same font as
$c_1$ will be treated as nonletters. The \\{hyphen\_char} for that font
must be between 0 and 255, otherwise hyphenation will not be attempted.
\TeX\ looks ahead for as many consecutive letters $c_1\ldots c_n$ as
possible; however, \|n must be less than 64, so a character that would
otherwise be $c_{64}$ is effectively not a letter. Furthermore $c_n$ must
not be in the middle of a ligature.  In this way we obtain a string of
letters $c_1\ldots c_n$ that are generated by nodes $p_a\ldots p_b$, where
$1\L\|a\L\|b+1\L\|m$. If $\|n\G5$, this string qualifies for hyphenation;
however,
\\{uc\_hyph} must be positive, if $c_1$ is uppercase.

The hyphenation process takes place in three stages. First, the candidate
sequence $c_1\ldots c_n$ is found; then potential positions for hyphens
are determined by referring to hyphenation tables; and finally, the nodes
$p_a\ldots p_b$ are replaced by a new sequence of nodes that includes the
discretionary breaks found.

Fortunately, we do not have to do all this calculation very often, because
of the way it has been taken out of \TeX's inner loop. For example, when
the second edition of the author's 700-page book {\sl Seminumerical
Algorithms} was typeset by \TeX, only about 1.2 hyphenations needed to be
tried per paragraph, since the line breaking algorithm needed to use two
passes on only about 5 per cent of the paragraphs.

\fi

\M892. The letters $c_1\ldots c_n$ that are candidates for hyphenation are
placed
into an array called \\{hc}; the number \|n is placed into \\{hn}; pointers to
nodes $p_a$ and~$p_b$ in the description above are placed into variables
\\{ha} and \\{hb}; and the font number is placed into \\{hf}.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{hc}: \37\&{array} $[0\to65]$ \1\&{of}\5
\\{halfword};\C{word to be hyphenated}\2\6
\4\\{hn}: \37\\{small\_number};\C{the number of positions occupied in \\{hc}}\6
\4$\\{ha},\39\\{hb}$: \37\\{pointer};\C{nodes $\\{ha}\to\\{hb}$ should be
replaced by the hyphenated result}\6
\4\\{hf}: \37\\{internal\_font\_number};\C{font number of the letters in %
\\{hc}}\6
\4\\{hu}: \37\&{array} $[1\to63]$ \1\&{of}\5
\\{ASCII\_code};\C{like \\{hc}, before conversion to lowercase}\2\6
\4\\{hyf\_char}: \37\\{integer};\C{hyphen character of the relevant font}\par
\fi

\M893. Hyphenation routines need a few more local variables.

\Y\P$\4\X862:Local variables for line breaking\X\mathrel{+}\S$\6
\4\|j: \37\\{small\_number};\C{an index into \\{hc} or \\{hu}}\6
\4\|c: \37$0\to255$;\C{character being considered for hyphenation}\par
\fi

\M894. When the following code is activated, the \\{line\_break} procedure is
in its
second pass, and \\{cur\_p} points to a glue node.

\Y\P$\4\X894:Try to hyphenate the following word\X\S$\6
\&{begin} \37$\|s\K\\{link}(\\{cur\_p})$;\6
\&{if} $\|s\I\\{null}$ \1\&{then}\6
\&{begin} \37\X896\*:Skip to node \\{ha}, or \&{goto} \\{done1} if no
hyphenation should be attempted\X;\6
\X897:Skip to node \\{hb}, putting letters into \\{hu} and \\{hc}\X;\6
\X899\*:Check that the nodes following \\{hb} permit hyphenation and that at
least five letters have been found, otherwise \&{goto} \\{done1}\X;\6
\\{hyphenate};\6
\&{end};\2\6
\4\\{done1}: \37\&{end}\par
\U section~866.\fi

\M895. \P$\X826:Declare subprocedures for \\{line\_break}\X\mathrel{+}\S$\6
\hbox{\4}\X906:Declare the function called \\{reconstitute}\X \6
\4\&{procedure}\1\  \37\\{hyphenate};\6
\4\&{label} \37$\\{done},\39\\{found},\39\\{not\_found},\39\\{found1},\39%
\\{exit}$;\6
\4\&{var} \37\X901:Local variables for hyphenation\X\2\6
\&{begin} \37\X923:Find hyphen locations for the word in \\{hc}\X;\6
\X902:If no hyphens were found, \&{return}\X;\6
\X903:Replace nodes $\\{ha}\to\\{hb}$ by a sequence of nodes that includes the
discretionary hyphens\X;\6
\4\\{exit}: \37\&{end};\par
\fi

\M896\*. The first thing we need to do is find the node \\{ha} that contains
the
first letter.

\Y\P$\4\X896\*:Skip to node \\{ha}, or \&{goto} \\{done1} if no hyphenation
should be attempted\X\S$\6
\~ \1\&{loop}\ \&{begin} \37\&{if} $\\{is\_char\_node}(\|s)$ \1\&{then}\6
\&{begin} \37$\|c\K\\{qo}(\\{character}(\|s))$;\5
$\\{hf}\K\\{font}(\|s)$;\6
\&{if} $\\{hf}=\\{font\_base}$ \1\&{then}\5
\&{goto} \37\\{done1};\C{$\\{is\_xchar\_node}(\|s)$}\2\6
\&{end}\6
\4\&{else} \&{if} $\\{type}(\|s)=\\{ligature\_node}$ \1\&{then}\6
\&{begin} \37$\|q\K\\{lig\_ptr}(\|s)$;\5
$\|c\K\\{qo}(\\{character}(\|q))$;\5
$\\{hf}\K\\{font}(\|q)$;\6
\&{end}\6
\4\&{else} \&{if} $(\\{type}(\|s)=\\{kern\_node})\W(\\{subtype}(\|s)=%
\\{normal})$ \1\&{then}\5
$\|c\K128$\6
\4\&{else} \&{if} $\\{type}(\|s)=\\{whatsit\_node}$ \1\&{then}\5
$\|c\K128$\6
\4\&{else} \&{goto} \37\\{done1};\2\2\2\2\6
\&{if} $\|c<128$ \1\&{then}\6
\&{if} $\\{lc\_code}(\|c)\I0$ \1\&{then}\6
\&{if} $(\\{lc\_code}(\|c)=\|c)\V(\\{uc\_hyph}>0)$ \1\&{then}\5
\&{goto} \37\\{done2}\6
\4\&{else} \&{goto} \37\\{done1};\2\2\2\6
$\|s\K\\{link}(\|s)$;\6
\&{end};\2\6
\4\\{done2}: \37$\\{hyf\_char}\K\\{hyphen\_char}[\\{hf}]$;\6
\&{if} $\\{hyf\_char}<0$ \1\&{then}\5
\&{goto} \37\\{done1};\2\6
\&{if} $\\{hyf\_char}>255$ \1\&{then}\5
\&{goto} \37\\{done1};\2\6
$\\{ha}\K\|s$\par
\U section~894.\fi

\M897. The word to be hyphenated is now moved to the \\{hu} and \\{hc} arrays.

\Y\P$\4\X897:Skip to node \\{hb}, putting letters into \\{hu} and \\{hc}\X\S$\6
$\\{hn}\K0$;\6
\~ \1\&{loop}\ \&{begin} \37\&{if} $\\{is\_char\_node}(\|s)$ \1\&{then}\6
\&{begin} \37\&{if} $\\{font}(\|s)\I\\{hf}$ \1\&{then}\5
\&{goto} \37\\{done3};\2\6
$\|c\K\\{qo}(\\{character}(\|s))$;\6
\&{if} $\|c\G128$ \1\&{then}\5
\&{goto} \37\\{done3};\2\6
\&{if} $(\\{lc\_code}(\|c)=0)\V(\\{hn}=63)$ \1\&{then}\5
\&{goto} \37\\{done3};\2\6
$\\{hb}\K\|s$;\5
$\\{incr}(\\{hn})$;\5
$\\{hu}[\\{hn}]\K\|c$;\5
$\\{hc}[\\{hn}]\K\\{lc\_code}(\|c)-1$;\6
\&{end}\6
\4\&{else} \&{if} $\\{type}(\|s)=\\{ligature\_node}$ \1\&{then}\5
\X898:Move the characters of a ligature node to \\{hu} and \\{hc}; but \&{goto}
\\{done3} if they are not all letters\X\6
\4\&{else} \&{if} $(\\{type}(\|s)\I\\{kern\_node})\V(\\{subtype}(\|s)\I%
\\{normal})$ \1\&{then}\5
\&{goto} \37\\{done3};\2\2\2\6
$\|s\K\\{link}(\|s)$;\6
\&{end};\2\6
\4\\{done3}: \37\par
\U section~894.\fi

\M898. We let \|j be the index of the character being stored when a ligature
node
is being expanded, since we do not want to advance \\{hn} until we are sure
that the entire ligature consists of letters. Note that it is possible
to get to \\{done3} with $\\{hn}=0$ and \\{hb} not set to any value.

\Y\P$\4\X898:Move the characters of a ligature node to \\{hu} and \\{hc}; but %
\&{goto} \\{done3} if they are not all letters\X\S$\6
\&{begin} \37$\|j\K\\{hn}$;\5
$\|q\K\\{lig\_ptr}(\|s)$;\6
\&{if} $\\{font}(\|q)\I\\{hf}$ \1\&{then}\5
\&{goto} \37\\{done3};\2\6
\1\&{repeat} \37$\|c\K\\{qo}(\\{character}(\|q))$;\6
\&{if} $\|c\G128$ \1\&{then}\5
\&{goto} \37\\{done3};\2\6
\&{if} $(\\{lc\_code}(\|c)=0)\V(\|j=63)$ \1\&{then}\5
\&{goto} \37\\{done3};\2\6
$\\{incr}(\|j)$;\5
$\\{hu}[\|j]\K\|c$;\5
$\\{hc}[\|j]\K\\{lc\_code}(\|c)-1$;\6
$\|q\K\\{link}(\|q)$;\6
\4\&{until}\5
$\|q=\\{null}$;\2\6
$\\{hb}\K\|s$;\5
$\\{hn}\K\|j$;\6
\&{end}\par
\U section~897.\fi

\M899\*. \P$\X899\*:Check that the nodes following \\{hb} permit hyphenation
and that at least five letters have been found, otherwise \&{goto} \\{done1}\X%
\S$\6
\&{if} $\\{hn}<5$ \1\&{then}\5
\&{goto} \37\\{done1};\2\6
\~ \1\&{loop}\ \&{begin} \37\&{if} $\R(\\{is\_char\_node}(\|s))$ \1\&{then}\6
\&{case} $\\{type}(\|s)$ \1\&{of}\6
\4\\{ligature\_node}: \37\\{do\_nothing};\6
\4\\{kern\_node}: \37\&{if} $\\{subtype}(\|s)\I\\{normal}$ \1\&{then}\5
\&{goto} \37\\{done4};\2\6
\4$\\{whatsit\_node},\39\\{glue\_node},\39\\{penalty\_node},\39\\{ins\_node},%
\39\\{adjust\_node},\39\\{mark\_node}$: \37\&{goto} \37\\{done4};\6
\4\&{othercases} \37\&{goto} \37\\{done1}\2\6
\&{endcases}\6
\4\&{else} \&{if} $\\{is\_xchar\_node}(\|s)$ \1\&{then}\5
\&{goto} \37\\{done1};\2\2\6
$\|s\K\\{link}(\|s)$;\6
\&{end};\2\6
\4\\{done4}: \37\par
\U section~894.\fi

\N900.  \[41] Post-hyphenation.
If a hyphen may be inserted between $\\{hc}[\|j]$ and $\\{hc}[\|j+1]$, the
hyphenation
procedure will set $\\{hyf}[\|j]$ to some small odd number. But before we look
at \TeX's hyphenation procedure, which is independent of the rest of the
line-breaking algorithm, let us consider what we will do with the hyphens
it finds, since it is better to work on this part of the program before
forgetting what \\{ha} and \\{hb}, etc., are all about.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{hyf}: \37\&{array} $[0\to64]$ \1\&{of}\5
$0\to9$;\C{odd values indicate discretionary hyphens}\2\par
\fi

\M901. \P$\X901:Local variables for hyphenation\X\S$\6
\4$\|i,\39\|j,\39\|l$: \37$0\to65$;\C{indices into \\{hc} or \\{hu}}\6
\4$\|q,\39\|r,\39\|s$: \37\\{pointer};\C{temporary registers for list
manipulation}\par
\A sections~912, 922, and~929.
\U section~895.\fi

\M902. \TeX\ will never insert a hyphen that has fewer than two letters before
it or fewer than three after it; hence, a five-letter word has comparatively
little chance of being hyphenated. If no hyphens have been found,
we can save time by not having to make any changes to the paragraph.

\Y\P$\4\X902:If no hyphens were found, \&{return}\X\S$\6
\&{for} $\|j\K2\mathrel{\&{to}}\\{hn}-3$ \1\&{do}\6
\&{if} $\\{odd}(\\{hyf}[\|j])$ \1\&{then}\5
\&{goto} \37\\{found1};\2\2\6
\&{return};\6
\4\\{found1}: \37\par
\U section~895.\fi

\M903. If hyphens are in fact going to be inserted, \TeX\ first deletes the
subsequence of nodes $\\{ha}\to\\{hb}$. The variable \|s will point to the node
preceding \\{ha}, and \|q will point to the node following \\{hb}, so that
things can be hooked up after we reconstitute the hyphenated word.

\Y\P$\4\X903:Replace nodes $\\{ha}\to\\{hb}$ by a sequence of nodes that
includes the discretionary hyphens\X\S$\6
$\|q\K\\{link}(\\{hb})$;\5
$\\{link}(\\{hb})\K\\{null}$;\5
$\|s\K\\{cur\_p}$;\6
\&{while} $\\{link}(\|s)\I\\{ha}$ \1\&{do}\5
$\|s\K\\{link}(\|s)$;\2\6
$\\{link}(\|s)\K\\{null}$;\5
$\\{flush\_node\_list}(\\{ha})$;\5
\X913:Reconstitute nodes for the hyphenated word, inserting discretionary
hyphens\X\par
\U section~895.\fi

\M904. We must now face the fact that the battle is not over, even though the
{\def\!{\kern-1pt}
hyphens have been found: The process of reconstituting a word can be nontrivial
because ligatures might change when a hyphen is present. {\sl The \TeX book\/}
discusses the difficulties of the word ``difficult'', but since fonts can
include highly general ligatures, the discretionary material surrounding a
hyphen can be even more complex than that. For example, suppose that
\.{abcdef} is a word in a font for which the only ligatures are \.{b\!c},
\.{c\!d}, \.{d\!e}, and \.{e\!f}. If this word is to permit hyphenation
between \.b and \.c, the two patterns with and without hyphenation are
$\.a\,\.b\,\.-\,\.{c\!d}\,\.{e\!f}$ and $\.a\,\.{b\!c}\,\.{d\!e}\,\.f$.
Thus the insertion of a hyphen might cause effects to ripple arbitrarily
far into the rest of the word. A further complication arises if additional
hyphens appear together with such rippling, e.g., if the word in the
example just given could also be hyphenated between \.c and \.d; \TeX\
avoids this by simply ignoring the additional hyphens in such weird cases.}

\fi

\M905. The processing is facilitated by a subroutine called \\{reconstitute}.
Given
an index~\|j, this function creates a node for the next character or ligature
found in the \\{hu} array starting at $\\{hu}[\|j]$, using font \\{hf}. For
example,
if $\\{hu}[\|j\to\|j+2]$ contains the three letters `f', `i', and `x', and if
font \\{hf} contains an `fi' ligature but no `fix' ligature, then %
\\{reconstitute}
will create a ligature node for `fi'. The index of the last character
consumed, in this case $\|j+1$, will be returned. Furthermore, a kern node
is created and appended, if kerning is called for between the consumed
character or ligature and the next (unconsumed) character.

A second parameter, \|n, gives the limit beyond which this procedure does not
advance. In other words, $\\{hu}[\|n]$ might be consumed, but $\\{hu}[\|n+1]$
is never
accessed.

The global variable \\{hyphen\_passed} is set to~\|k if this procedure
consumes two characters $\\{hu}[\|k]$ and $\\{hu}[\|k+1]$ such that $\\{hyf}[%
\|k]$ is odd,
i.e., if the ligature might have to be broken by a hyphen, or if a kern is
inserted between $\\{hu}[\|k]$ and $\\{hu}[\|k+1]$.  If this condition holds
for more
than one value of \|k, the smallest value is used; and if the condition
holds for no values of \|k, \\{hyphen\_passed} is set to zero.

After \\{reconstitute} has acted, $\\{link}(\\{hold\_head})$ points to the
character
or ligature node that was created, and $\\{link}(\\{link}(\\{hold\_head}))$
will either
be \\{null} or a pointer to the kern node that was appended.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{hyphen\_passed}: \37\\{small\_number};\C{first hyphen in a ligature, if
any}\par
\fi

\M906. \P$\X906:Declare the function called \\{reconstitute}\X\S$\6
\4\&{function}\1\  \37$\\{reconstitute}(\|j,\39\|n:\\{small\_number})$: \37%
\\{small\_number};\6
\4\&{label} \37$\\{continue},\39\\{done}$;\6
\4\&{var} \37\|p: \37\\{pointer};\C{a node being created}\6
\|s: \37\\{pointer};\C{a node being appended to}\6
\|q: \37\\{four\_quarters};\C{character information or a lig/kern instruction}\6
\|c: \37\\{quarterword};\C{current character}\6
\|d: \37\\{quarterword};\C{current character or ligature}\6
\|w: \37\\{scaled};\C{amount of kerning}\6
\|r: \37$0\to\\{font\_mem\_size}$;\C{position of current lig/kern instruction}%
\2\6
\&{begin} \37\X907:Build a list of characters in a maximal ligature, and set %
\|w to the amount of kerning that should follow\X;\6
\X910:If the list has more than one element, create a ligature node\X;\6
\X911:Attach kerning, if $\|w\I0$\X;\6
$\\{reconstitute}\K\|j$;\6
\&{end};\par
\U section~895.\fi

\M907. \P$\X907:Build a list of characters in a maximal ligature, and set \|w
to the amount of kerning that should follow\X\S$\6
$\\{hyphen\_passed}\K0$;\5
$\|s\K\\{hold\_head}$;\5
$\|w\K0$;\5
$\|d\K\\{qi}(\\{hu}[\|j])$;\5
$\|c\K\|d$;\6
\~ \1\&{loop}\ \&{begin} \37\\{continue}: \37$\|p\K\\{get\_avail}$;\5
$\\{font}(\|p)\K\\{hf}$;\5
$\\{character}(\|p)\K\|c$;\5
$\\{link}(\|s)\K\|p$;\6
\X908:Look for a ligature or kern between \|d and the following character;
update the data structure and \&{goto} \\{continue} if a ligature is found,
otherwise update~\|w and \&{goto} \\{done}\X;\6
\&{end};\2\6
\4\\{done}: \37\par
\U section~906.\fi

\M908. \P$\X908:Look for a ligature or kern between \|d and the following
character; update the data structure and \&{goto} \\{continue} if a ligature is
found, otherwise update~\|w and \&{goto} \\{done}\X\S$\6
\&{if} $\|j=\|n$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
$\|q\K\\{char\_info}(\\{hf})(\|d)$;\6
\&{if} $\\{char\_tag}(\|q)\I\\{lig\_tag}$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
$\|r\K\\{lig\_kern\_start}(\\{hf})(\|q)$;\5
$\|c\K\\{qi}(\\{hu}[\|j+1])$;\6
\~ \1\&{loop}\ \&{begin} \37$\|q\K\\{font\_info}[\|r].\\{qqqq}$;\6
\&{if} $\\{next\_char}(\|q)=\|c$ \1\&{then}\6
\&{begin} \37\&{if} $\\{odd}(\\{hyf}[\|j])\W(\\{hyphen\_passed}=0)$ \1\&{then}\5
$\\{hyphen\_passed}\K\|j$;\2\6
\&{if} $\\{op\_bit}(\|q)<\\{kern\_flag}$ \1\&{then}\5
\X909:Append to the ligature and \&{goto} \\{continue}\X\6
\4\&{else} \&{begin} \37$\|w\K\\{char\_kern}(\\{hf})(\|q)$;\5
\&{goto} \37\\{done};\6
\&{end};\2\6
\&{end}\6
\4\&{else} \&{if} $\\{stop\_bit}(\|q)<\\{stop\_flag}$ \1\&{then}\5
$\\{incr}(\|r)$\6
\4\&{else} \&{goto} \37\\{done};\2\2\6
\&{end}\2\par
\U section~907.\fi

\M909. \P$\X909:Append to the ligature and \&{goto} \\{continue}\X\S$\6
\&{begin} \37$\|d\K\\{rem\_byte}(\|q)$;\5
$\\{incr}(\|j)$;\5
$\|s\K\|p$;\5
\&{goto} \37\\{continue};\6
\&{end}\par
\U section~908.\fi

\M910. After the list has been built, $\\{link}(\|s)$ points to the final list
element.

\Y\P$\4\X910:If the list has more than one element, create a ligature node\X\S$%
\6
\&{if} $\|s\I\\{hold\_head}$ \1\&{then}\6
\&{begin} \37$\|p\K\\{new\_ligature}(\\{hf},\39\|d,\39\\{link}(\\{hold%
\_head}))$;\5
$\\{link}(\\{hold\_head})\K\|p$;\6
\&{end}\2\par
\U section~906.\fi

\M911. \P$\X911:Attach kerning, if $\|w\I0$\X\S$\6
\&{if} $\|w\I0$ \1\&{then}\5
$\\{link}(\\{link}(\\{hold\_head}))\K\\{new\_kern}(\|w)$\2\par
\U section~906.\fi

\M912. Okay, we're ready to insert the potential hyphenations that were found.
When the following program is executed, we want to append the word
$\\{hu}[1\to\\{hn}]$ after node \|s, and node \|q should be appended to the
result.
During this process, the variable \|i will be a temporary counter or an
index into \\{hu}; the variable \|j will be an index to our current position
in \\{hu}; the variable \|l will be the counterpart of \|j, in a discretionary
branch; the variable \|r will point to new nodes being created; and
we need a few new local variables:

\Y\P$\4\X901:Local variables for hyphenation\X\mathrel{+}\S$\6
\4$\\{major\_tail},\39\\{minor\_tail}$: \37\\{pointer};\C{the end of lists in
the main and 	discretionary branches being reconstructed}\6
\4\|c: \37\\{ASCII\_code};\C{character temporarily replaced by a hyphen}\6
\4\\{hyf\_node}: \37\\{pointer};\C{the hyphen, if it exists}\par
\fi

\M913. When the following code is performed, $\\{hyf}[\|j]$ will be zero for $%
\|j=1$
and for $\|j\G\\{hn}-2$.

\Y\P$\4\X913:Reconstitute nodes for the hyphenated word, inserting
discretionary hyphens\X\S$\6
$\|j\K0$;\6
\1\&{repeat} \37$\|l\K\|j$;\5
$\|j\K\\{reconstitute}(\|j+1,\39\\{hn})$;\6
\&{if} $\\{hyphen\_passed}\I0$ \1\&{then}\5
\X914:Create and append a discretionary node as an alternative to the ligature,
and continue to develop both branches until they become equivalent\X\6
\4\&{else} \&{begin} \37$\\{link}(\|s)\K\\{link}(\\{hold\_head})$;\5
$\|s\K\\{link}(\|s)$;\6
\&{if} $\\{link}(\|s)\I\\{null}$ \1\&{then}\5
$\|s\K\\{link}(\|s)$;\2\6
\&{end};\2\6
\&{if} $\\{odd}(\\{hyf}[\|j])$ \1\&{then}\5
\X918:Insert a discretionary hyphen after \|s\X;\2\6
\4\&{until}\5
$\|j=\\{hn}$;\2\6
$\\{link}(\|s)\K\|q$\par
\U section~903.\fi

\M914. \P$\X914:Create and append a discretionary node as an alternative to the
ligature, and continue to develop both branches until they become equivalent\X%
\S$\6
\&{begin} \37$\|r\K\\{get\_node}(\\{small\_node\_size})$;\5
$\\{link}(\|s)\K\|r$;\5
$\\{link}(\|r)\K\\{link}(\\{hold\_head})$;\5
$\\{type}(\|r)\K\\{disc\_node}$;\5
$\\{major\_tail}\K\\{link}(\\{hold\_head})$;\6
\&{if} $\\{link}(\\{major\_tail})\I\\{null}$ \1\&{then}\5
$\\{major\_tail}\K\\{link}(\\{major\_tail})$;\2\6
$\|i\K\\{hyphen\_passed}$;\5
\X915:Put the \(c)characters $\\{hu}[\|l+1\to\|i]$ and a hyphen into $\\{pre%
\_break}(\|r)$\X;\6
\X916:Put the \(c)characters $\\{hu}[\|i+1\to\,]$ into $\\{post\_break}(\|r)$,
appending to this list and to \\{major\_tail} until synchronization has been
achieved\X;\6
\X917:Move pointer \|s to the end of the current list, and set $\\{replace%
\_count}(\|r)$ appropriately\X;\6
\&{end}\par
\U section~913.\fi

\M915. The new hyphen might combine with the previous character via ligature
or kern. At this point we have $\|l<\|i\L\|j$ and $\|i\L\\{hn}-3$.

\Y\P$\4\X915:Put the \(c)characters $\\{hu}[\|l+1\to\|i]$ and a hyphen into $%
\\{pre\_break}(\|r)$\X\S$\6
$\\{minor\_tail}\K\\{null}$;\5
$\\{hyf\_node}\K\\{new\_character}(\\{hf},\39\\{hyf\_char})$;\6
\&{if} $\\{hyf\_node}\I\\{null}$ \1\&{then}\6
\&{begin} \37$\\{incr}(\|i)$;\5
$\|c\K\\{hu}[\|i]$;\5
$\\{hu}[\|i]\K\\{hyf\_char}$;\6
\&{end};\2\6
\1\&{repeat} \37$\|l\K\\{reconstitute}(\|l+1,\39\|i)$;\6
\&{if} $\\{minor\_tail}=\\{null}$ \1\&{then}\5
$\\{pre\_break}(\|r)\K\\{link}(\\{hold\_head})$\6
\4\&{else} $\\{link}(\\{minor\_tail})\K\\{link}(\\{hold\_head})$;\2\6
$\\{minor\_tail}\K\\{link}(\\{hold\_head})$;\6
\&{if} $\\{link}(\\{minor\_tail})\I\\{null}$ \1\&{then}\5
$\\{minor\_tail}\K\\{link}(\\{minor\_tail})$;\2\6
\4\&{until}\5
$\|l=\|i$;\2\6
\&{if} $\\{hyf\_node}\I\\{null}$ \1\&{then}\6
\&{begin} \37$\\{hu}[\|i]\K\|c$;\C{restore the character in the hyphen
position}\6
$\\{free\_avail}(\\{hyf\_node})$;\5
$\\{decr}(\|i)$;\5
$\|l\K\|i$;\6
\&{end};\2\6
$\\{hyf}[\|i]\K0$\par
\U section~914.\fi

\M916. The synchronization algorithm begins with $\|l=\|i\L\|j$.

\Y\P$\4\X916:Put the \(c)characters $\\{hu}[\|i+1\to\,]$ into $\\{post\_break}(%
\|r)$, appending to this list and to \\{major\_tail} until synchronization has
been achieved\X\S$\6
$\\{minor\_tail}\K\\{null}$;\5
$\\{post\_break}(\|r)\K\\{null}$;\6
\&{while} $\|l<\|j$ \1\&{do}\6
\&{begin} \37\1\&{repeat} \37$\|l\K\\{reconstitute}(\|l+1,\39\\{hn})$;\6
\&{if} $\\{minor\_tail}=\\{null}$ \1\&{then}\5
$\\{post\_break}(\|r)\K\\{link}(\\{hold\_head})$\6
\4\&{else} $\\{link}(\\{minor\_tail})\K\\{link}(\\{hold\_head})$;\2\6
$\\{minor\_tail}\K\\{link}(\\{hold\_head})$;\6
\&{if} $\\{link}(\\{minor\_tail})\I\\{null}$ \1\&{then}\6
\&{begin} \37$\\{hyf}[\|l]\K0$;\5
$\\{minor\_tail}\K\\{link}(\\{minor\_tail})$;\C{kern present}\6
\&{end};\2\6
\4\&{until}\5
$\|l\G\|j$;\2\6
\&{while} $\|l>\|j$ \1\&{do}\6
\&{begin} \37$\|j\K\\{reconstitute}(\|j+1,\39\\{hn})$;\5
$\\{link}(\\{major\_tail})\K\\{link}(\\{hold\_head})$;\5
$\\{major\_tail}\K\\{link}(\\{hold\_head})$;\6
\&{if} $\\{link}(\\{major\_tail})\I\\{null}$ \1\&{then}\6
\&{begin} \37$\\{hyf}[\|j]\K0$;\5
$\\{major\_tail}\K\\{link}(\\{major\_tail})$;\C{kern present}\6
\&{end};\2\6
\&{end};\2\6
\&{end}\2\par
\U section~914.\fi

\M917. \P$\X917:Move pointer \|s to the end of the current list, and set $%
\\{replace\_count}(\|r)$ appropriately\X\S$\6
$\|i\K0$;\5
$\|s\K\|r$;\6
\&{while} $\\{link}(\|s)\I\\{null}$ \1\&{do}\6
\&{begin} \37$\\{incr}(\|i)$;\5
$\|s\K\\{link}(\|s)$;\6
\&{end};\2\6
$\\{replace\_count}(\|r)\K\|i$\par
\U section~914.\fi

\M918. At this point $\\{link}(\|s)$ is \\{null}.

\Y\P$\4\X918:Insert a discretionary hyphen after \|s\X\S$\6
\&{begin} \37$\|r\K\\{new\_disc}$;\5
$\\{pre\_break}(\|r)\K\\{new\_character}(\\{hf},\39\\{hyf\_char})$;\5
$\\{link}(\|s)\K\|r$;\5
$\|s\K\|r$;\6
\&{end}\par
\U section~913.\fi

\N919.  \[42] Hyphenation.
When a word $\\{hc}[1\to\\{hn}]$ has been set up to contain a candidate for
hyphenation,
\TeX\ first looks to see if it is in the user's exception dictionary. If not,
hyphens are inserted based on patterns that appear within the given word,
using an algorithm due to Frank~M. Liang.

Let's consider Liang's method first, since it is much more interesting than the
exception-lookup routine.  The algorithm begins by setting $\\{hyf}[\|j]$ to
zero
for all \|j, and invalid characters are inserted into $\\{hc}[0]$
and $\\{hc}[\\{hn}+1]$ to serve as delimiters. Then a reasonably fast method is
used to see which of a given set of patterns occurs in the word
$\\{hc}[0\to(\\{hn}+1)]$. Each pattern $p_1\ldots p_k$ of length \|k has an
associated
sequence of $\|k+1$ numbers $n_0\ldots n_k$; and if the pattern occurs in
$\\{hc}[(\|j+1)\to(\|j+\|k)]$, \TeX\ will set $\\{hyf}[\|j+\|i]\K\hbox{max}(%
\\{hyf}[\|j+\|i],\hbox{$n_i$})$ for
$0\L\|i\L\|k$. After this has been done for each pattern that occurs, a
discretionary hyphen will be inserted between $\\{hc}[\|j]$ and $\\{hc}[\|j+1]$
when
$\\{hyf}[\|j]$ is odd, as we have already seen.

The set of patterns $p_1\ldots p_k$ and associated numbers $n_0\ldots n_k$
depends, of course, on the language whose words are being hyphenated, and
on the degree of hyphenation that is desired. A method for finding
appropriate \|p's and \|n's, from a given dictionary of words and acceptable
hyphenations, is discussed in Liang's Ph.D. thesis (Stanford University,
1983); \TeX\ simply starts with the patterns and works from there.

\fi

\M920. The patterns are stored in a compact table that is also efficient for
retrieval, using a variant of ``trie memory'' [cf.\ {\sl The Art of
Computer Programming \bf3} (1973), 481--505]. We can find each pattern
$p_1\ldots p_k$ by setting $\hbox{$z_1$}\K\hbox{$p_1$}$ and then, for $1<\|i\L%
\|k$,
setting $\hbox{$z_i$}\K\\{trie\_link}\hbox{$(z_{i-1})+p_i$}$; the pattern will
be
identified by the number $z_k$. Since all the pattern information is
packed together into a single \\{trie\_link} array, it is necessary to
prevent confusion between the data from inequivalent patterns, so another
table is provided such that \\{trie\_char}\hbox{$(z_i)=p_i$} for all \|i. There
is also a table \\{trie\_op}$(z_k)$ to identify the numbers $n_0\ldots n_k$
associated with $p_1\ldots p_k$.

Comparatively few different number sequences $n_0\ldots n_k$ actually occur,
since most of the \|n's are generally zero. Therefore the number sequences
are encoded in such a way that \\{trie\_op}$(z_k)$ is only one byte long.
If $\\{trie\_op}(\hbox{$z_k$})\I\\{min\_quarterword}$, when $p_1\ldots p_k$ has
matched
the letters in $\\{hc}[(\|l-\|k+1)\to\|l\,]$, we perform all of the required
operations
for this pattern by carrying out the following little program: Set
$\|v\K\\{trie\_op}(\hbox{$z_k$})$. Then set $\\{hyf}[\|l-\\{hyf\_distance}[%
\|v]]\K\hbox{max}(\\{hyf}[\|l-\\{hyf\_distance}[\|v]],\\{hyf\_num}[\|v])$, and
$\|v\K\\{hyf\_next}[\|v]$; repeat, if
necessary, until $\|v=\\{min\_quarterword}$.

\Y\P$\4\X18:Types in the outer block\X\mathrel{+}\S$\6
$\\{trie\_pointer}=0\to\\{trie\_size}$;\C{an index into \\{trie}}\par
\fi

\M921. \P\D \37$\\{trie\_link}(\#)\S\\{trie}[\#].\\{rh}$\C{``downward'' link in
a trie}\par
\P\D \37$\\{trie\_char}(\#)\S\\{trie}[\#].\\{b1}$\C{character matched at this
trie location}\par
\P\D \37$\\{trie\_op}(\#)\S\\{trie}[\#].\\{b0}$\C{program for hyphenation at
this trie location}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{trie}: \37\&{array} $[\\{trie\_pointer}]$ \1\&{of}\5
\\{two\_halves};\C{\\{trie\_link}, \\{trie\_char}, \\{trie\_op}}\2\6
\4\\{hyf\_distance}: \37\&{array} $[\\{quarterword}]$ \1\&{of}\5
\\{small\_number};\C{position $\|k-\|j$ of $n_j$}\2\6
\4\\{hyf\_num}: \37\&{array} $[\\{quarterword}]$ \1\&{of}\5
\\{small\_number};\C{value of $n_j$}\2\6
\4\\{hyf\_next}: \37\&{array} $[\\{quarterword}]$ \1\&{of}\5
\\{quarterword};\C{continuation of this \\{trie\_op}}\2\par
\fi

\M922. \P$\X901:Local variables for hyphenation\X\mathrel{+}\S$\6
\4\|z: \37\\{trie\_pointer};\C{an index into \\{trie}}\6
\4\|v: \37\\{quarterword};\C{an index into \\{hyf\_distance}, etc.}\par
\fi

\M923. Assuming that these auxiliary tables have been set up properly, the
hyphenation algorithm is quite short. In the following code we set $\\{hc}[%
\\{hn}+2]$
to the impossible value 256, in order to guarantee that $\\{hc}[\\{hn}+3]$ will
never be fetched.

\Y\P$\4\X923:Find hyphen locations for the word in \\{hc}\X\S$\6
\&{for} $\|j\K0\mathrel{\&{to}}\\{hn}$ \1\&{do}\5
$\\{hyf}[\|j]\K0$;\2\6
\X930:Look for the word $\\{hc}[1\to\\{hn}]$ in the exception table, and %
\&{goto} \\{found} (with \\{hyf} containing the hyphens) if an entry is found%
\X;\6
$\\{hc}[0]\K127$;\5
$\\{hc}[\\{hn}+1]\K127$;\5
$\\{hc}[\\{hn}+2]\K256$;\C{insert delimiters}\6
\&{for} $\|j\K0\mathrel{\&{to}}\\{hn}-2$ \1\&{do}\6
\&{begin} \37$\|z\K\\{hc}[\|j]$;\5
$\|l\K\|j$;\6
\&{while} $\\{hc}[\|l]=\\{trie\_char}(\|z)$ \1\&{do}\6
\&{begin} \37\&{if} $\\{trie\_op}(\|z)\I\\{min\_quarterword}$ \1\&{then}\5
\X924:Store \(m)maximum values in the \\{hyf} table\X;\2\6
$\\{incr}(\|l)$;\5
$\|z\K\\{trie\_link}(\|z)+\\{hc}[\|l]$;\6
\&{end};\2\6
\&{end};\2\6
\4\\{found}: \37$\\{hyf}[1]\K0$;\5
$\\{hyf}[\\{hn}-2]\K0$;\5
$\\{hyf}[\\{hn}-1]\K0$;\5
$\\{hyf}[\\{hn}]\K0$\par
\U section~895.\fi

\M924. \P$\X924:Store \(m)maximum values in the \\{hyf} table\X\S$\6
\&{begin} \37$\|v\K\\{trie\_op}(\|z)$;\6
\1\&{repeat} \37$\|i\K\|l-\\{hyf\_distance}[\|v]$;\6
\&{if} $\\{hyf\_num}[\|v]>\\{hyf}[\|i]$ \1\&{then}\5
$\\{hyf}[\|i]\K\\{hyf\_num}[\|v]$;\2\6
$\|v\K\\{hyf\_next}[\|v]$;\6
\4\&{until}\5
$\|v=\\{min\_quarterword}$;\2\6
\&{end}\par
\U section~923.\fi

\M925. The exception table that is built by \TeX's \.{\\hyphenation} primitive
is
organized as an ordered hash table [cf.\ Amble and Knuth, {\sl The Computer
Journal\/ \bf17} (1974), 135--142] using linear probing. If $\alpha$ and
$\beta$ are words, we will say that $\alpha<\beta$ if $\vert\alpha\vert<
\vert\beta\vert$ or if $\vert\alpha\vert=\vert\beta\vert$ and
$\alpha$ is lexicographically smaller than $\beta$. (The notation $\vert
\alpha\vert$ stands for the length of $\alpha$.) The idea of ordered hashing
is to arrange the table so that a given word $\alpha$ can be sought by
computing
a hash address $h=h(\alpha)$ and then looking in table positions \|h, $\|h-1$,
\dots, until encountering the first word $\L\alpha$. If this word is
different from $\alpha$, we can conclude that $\alpha$ is not in the table.

The words in the table point to lists in \\{mem} that specify hyphen positions
in their \\{info} fields. The list for $c_1\ldots c_n$ contains \|k if
the word $c_1\ldots c_n$ has a discretionary hyphen between $c_k$ and
$c_{k+1}$.

\Y\P$\4\X18:Types in the outer block\X\mathrel{+}\S$\6
$\\{hyph\_pointer}=0\to\\{hyph\_size}$;\C{an index into the ordered hash table}%
\par
\fi

\M926. \P$\X13:Global variables\X\mathrel{+}\S$\6
\4\\{hyph\_word}: \37\&{array} $[\\{hyph\_pointer}]$ \1\&{of}\5
\\{str\_number};\C{exception words}\2\6
\4\\{hyph\_list}: \37\&{array} $[\\{hyph\_pointer}]$ \1\&{of}\5
\\{pointer};\C{list of hyphen positions}\2\6
\4\\{hyph\_count}: \37\\{hyph\_pointer};\C{the number of words in the exception
dictionary}\par
\fi

\M927. \P$\X19:Local variables for initialization\X\mathrel{+}\S$\6
\4\|z: \37\\{hyph\_pointer};\C{runs through the exception dictionary}\par
\fi

\M928. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
\&{for} $\|z\K0\mathrel{\&{to}}\\{hyph\_size}$ \1\&{do}\6
\&{begin} \37$\\{hyph\_word}[\|z]\K0$;\5
$\\{hyph\_list}[\|z]\K\\{null}$;\6
\&{end};\2\6
$\\{hyph\_count}\K0$;\par
\fi

\M929. The algorithm for exception lookup is quite simple, as soon as we have
a few more local variables to work with.

\Y\P$\4\X901:Local variables for hyphenation\X\mathrel{+}\S$\6
\4\|h: \37\\{hyph\_pointer};\C{an index into \\{hyph\_word} and \\{hyph\_list}}%
\6
\4\|k: \37\\{str\_number};\C{an index into \\{str\_start}}\6
\4\|u: \37\\{pool\_pointer};\C{an index into \\{str\_pool}}\par
\fi

\M930. First we compute the hash code \|h, then we search until we either
find the word or we don't.

\Y\P$\4\X930:Look for the word $\\{hc}[1\to\\{hn}]$ in the exception table, and
\&{goto} \\{found} (with \\{hyf} containing the hyphens) if an entry is found\X%
\S$\6
$\|h\K\\{hc}[1]$;\6
\&{for} $\|j\K2\mathrel{\&{to}}\\{hn}$ \1\&{do}\5
$\|h\K(\|h+\|h+\\{hc}[\|j])\mathbin{\&{mod}}\\{hyph\_size}$;\2\6
\~ \1\&{loop}\ \&{begin} \37\X931:If the string $\\{hyph\_word}[\|h]$ is less
than \(hc)$\\{hc}[1\to\\{hn}]$, \&{goto} \\{not\_found}; but if the two strings
are equal, set \\{hyf} to the hyphen positions and \&{goto} \\{found}\X;\6
\&{if} $\|h>0$ \1\&{then}\5
$\\{decr}(\|h)$\ \&{else} $\|h\K\\{hyph\_size}$;\2\6
\&{end};\2\6
\4\\{not\_found}: \37\par
\U section~923.\fi

\M931. \P$\X931:If the string $\\{hyph\_word}[\|h]$ is less than \(hc)$\\{hc}[1%
\to\\{hn}]$, \&{goto} \\{not\_found}; but if the two strings are equal, set %
\\{hyf} to the hyphen positions and \&{goto} \\{found}\X\S$\6
$\|k\K\\{hyph\_word}[\|h]$;\6
\&{if} $\|k=0$ \1\&{then}\5
\&{goto} \37\\{not\_found};\2\6
\&{if} $\\{length}(\|k)<\\{hn}$ \1\&{then}\5
\&{goto} \37\\{not\_found};\2\6
\&{if} $\\{length}(\|k)=\\{hn}$ \1\&{then}\6
\&{begin} \37$\|j\K1$;\5
$\|u\K\\{str\_start}[\|k]$;\6
\1\&{repeat} \37\&{if} $\\{str\_pool}[\|u]<\\{hc}[\|j]$ \1\&{then}\5
\&{goto} \37\\{not\_found};\2\6
\&{if} $\\{str\_pool}[\|u]>\\{hc}[\|j]$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
$\\{incr}(\|j)$;\5
$\\{incr}(\|u)$;\6
\4\&{until}\5
$\|j>\\{hn}$;\2\6
\X932:Insert hyphens as specified in $\\{hyph\_list}[\|h]$\X;\6
\&{goto} \37\\{found};\6
\&{end};\2\6
\4\\{done}: \37\par
\U section~930.\fi

\M932. \P$\X932:Insert hyphens as specified in $\\{hyph\_list}[\|h]$\X\S$\6
$\|s\K\\{hyph\_list}[\|h]$;\6
\&{while} $\|s\I\\{null}$ \1\&{do}\6
\&{begin} \37$\\{hyf}[\\{info}(\|s)]\K1$;\5
$\|s\K\\{link}(\|s)$;\6
\&{end}\2\par
\U section~931.\fi

\M933. \P$\X933:Search \\{hyph\_list} for pointers to \|p\X\S$\6
\&{for} $\|q\K0\mathrel{\&{to}}\\{hyph\_size}$ \1\&{do}\6
\&{begin} \37\&{if} $\\{hyph\_list}[\|q]=\|p$ \1\&{then}\6
\&{begin} \37$\\{print\_nl}(\.{"HYPH("})$;\5
$\\{print\_int}(\|q)$;\5
$\\{print\_char}(\.{")"})$;\6
\&{end};\2\6
\&{end}\2\par
\U section~172.\fi

\M934. We have now completed the hyphenation routine, so the \\{line\_break}
procedure
is finished at last. Since the hyphenation exception table is fresh in our
minds, it's a good time to deal with the routine that adds new entries to it.

When \TeX\ has scanned `\.{\\hyphenation}', it calls on a procedure named
\\{new\_hyph\_exceptions} to do the right thing.

\Y\P\4\&{procedure}\1\  \37\\{new\_hyph\_exceptions};\C{enters new exceptions}\6
\4\&{label} \37$\\{reswitch},\39\\{exit},\39\\{found},\39\\{not\_found},\39%
\\{done}$;\6
\4\&{var} \37\|n: \37\\{small\_number};\C{length of current word}\6
\|j: \37\\{small\_number};\C{an index into \\{hc}}\6
\|h: \37\\{hyph\_pointer};\C{an index into \\{hyph\_word} and \\{hyph\_list}}\6
\|k: \37\\{str\_number};\C{an index into \\{str\_start}}\6
\|p: \37\\{pointer};\C{head of a list of hyphen positions}\6
\|q: \37\\{pointer};\C{used when creating a new node for list \|p}\6
$\|s,\39\|t$: \37\\{str\_number};\C{strings being compared or stored}\6
$\|u,\39\|v$: \37\\{pool\_pointer};\C{indices into \\{str\_pool}}\2\6
\&{begin} \37\\{scan\_left\_brace};\C{a left brace must follow \.{%
\\hyphenation}}\6
\X935:Enter as many hyphenation exceptions as are listed, until coming to a
right brace; then skip an optional space and \&{return}\X;\6
\4\\{exit}: \37\&{end};\par
\fi

\M935. \P$\X935:Enter as many hyphenation exceptions as are listed, until
coming to a right brace; then skip an optional space and \&{return}\X\S$\6
$\|n\K0$;\5
$\|p\K\\{null}$;\6
\~ \1\&{loop}\ \&{begin} \37\\{get\_x\_token};\6
\4\\{reswitch}: \37\&{case} $\\{cur\_cmd}$ \1\&{of}\6
\4$\\{letter},\39\\{other\_char},\39\\{char\_given}$: \37\X937:Append a new
letter or hyphen\X;\6
\4\\{char\_num}: \37\&{begin} \37\\{scan\_char\_num};\5
$\\{cur\_chr}\K\\{cur\_val}$;\5
$\\{cur\_cmd}\K\\{char\_given}$;\5
\&{goto} \37\\{reswitch};\6
\&{end};\6
\4$\\{spacer},\39\\{right\_brace}$: \37\&{begin} \37\&{if} $\|n>4$ \1\&{then}\5
\X939:Enter a hyphenation exception\X;\2\6
\&{if} $\\{cur\_cmd}=\\{right\_brace}$ \1\&{then}\5
\&{return};\2\6
$\|n\K0$;\5
$\|p\K\\{null}$;\6
\&{end};\6
\4\&{othercases} \37\X936:Give improper \.{\\hyphenation} error\X\2\6
\&{endcases};\6
\&{end}\2\par
\U section~934.\fi

\M936. \P$\X936:Give improper \.{\\hyphenation} error\X\S$\6
\&{begin} \37$\\{print\_err}(\.{"Improper\ "})$;\5
$\\{print\_esc}(\.{"hyphenation"})$;\5
$\\{print}(\.{"\ will\ be\ flushed"})$;\5
$\\{help2}(\.{"Hyphenation\ exceptions\ must\ contain\ only\ letters"})$\6
$(\.{"and\ hyphens.\ But\ continue;\ I\'ll\ forgive\ and\ forget."})$;\5
\\{error};\6
\&{end}\par
\U section~935.\fi

\M937. \P$\X937:Append a new letter or hyphen\X\S$\6
\&{if} $\\{cur\_chr}=\.{"-"}$ \1\&{then}\5
\X938:Append the value \|n to list \|p\X\6
\4\&{else} \&{begin} \37\&{if} $(\\{cur\_chr}>127)\V(\\{lc\_code}(\\{cur%
\_chr})=0)$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Not\ a\ letter"})$;\5
$\\{help2}(\.{"Letters\ in\ \\hyphenation\ words\ must\ have\ \\lccode>0."})$\6
$(\.{"Proceed;\ I\'ll\ ignore\ the\ character\ I\ just\ read."})$;\5
\\{error};\6
\&{end}\6
\4\&{else} \&{if} $\|n<63$ \1\&{then}\6
\&{begin} \37$\\{incr}(\|n)$;\5
$\\{hc}[\|n]\K\\{lc\_code}(\\{cur\_chr})-1$;\6
\&{end};\2\2\6
\&{end}\2\par
\U section~935.\fi

\M938. \P$\X938:Append the value \|n to list \|p\X\S$\6
\&{begin} \37\&{if} $\|n>1$ \1\&{then}\6
\&{begin} \37$\|q\K\\{get\_avail}$;\5
$\\{link}(\|q)\K\|p$;\5
$\\{info}(\|q)\K\|n$;\5
$\|p\K\|q$;\6
\&{end};\2\6
\&{end}\par
\U section~937.\fi

\M939. \P$\X939:Enter a hyphenation exception\X\S$\6
\&{begin} \37$\\{str\_room}(\|n)$;\5
$\|h\K0$;\6
\&{for} $\|j\K1\mathrel{\&{to}}\|n$ \1\&{do}\6
\&{begin} \37$\|h\K(\|h+\|h+\\{hc}[\|j])\mathbin{\&{mod}}\\{hyph\_size}$;\5
$\\{append\_char}(\\{hc}[\|j])$;\6
\&{end};\2\6
$\|s\K\\{make\_string}$;\6
\~ \1\&{loop}\ \&{begin} \37\&{if} $\|p=\\{null}$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
\&{if} $\\{info}(\|p)<\|n-2$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
$\|q\K\\{link}(\|p)$;\5
$\\{free\_avail}(\|p)$;\5
$\|p\K\|q$;\C{eliminate hyphens that \TeX\ doesn't like}\6
\&{end};\2\6
\4\\{done}: \37\X940:Insert the \(p)pair $(\|s,\|p)$ into the exception table%
\X;\6
\&{end}\par
\U section~935.\fi

\M940. \P$\X940:Insert the \(p)pair $(\|s,\|p)$ into the exception table\X\S$\6
\&{if} $\\{hyph\_count}=\\{hyph\_size}$ \1\&{then}\5
$\\{overflow}(\.{"exception\ dictionary"},\39\\{hyph\_size})$;\2\6
$\\{incr}(\\{hyph\_count})$;\6
\&{while} $\\{hyph\_word}[\|h]\I0$ \1\&{do}\6
\&{begin} \37\X941:If the string $\\{hyph\_word}[\|h]$ is less than \(or)or
equal to \|s, interchange $(\\{hyph\_word}[\|h],\\{hyph\_list}[\|h])$ with $(%
\|s,\|p)$\X;\6
\&{if} $\|h>0$ \1\&{then}\5
$\\{decr}(\|h)$\ \&{else} $\|h\K\\{hyph\_size}$;\2\6
\&{end};\2\6
$\\{hyph\_word}[\|h]\K\|s$;\5
$\\{hyph\_list}[\|h]\K\|p$\par
\U section~939.\fi

\M941. \P$\X941:If the string $\\{hyph\_word}[\|h]$ is less than \(or)or equal
to \|s, interchange $(\\{hyph\_word}[\|h],\\{hyph\_list}[\|h])$ with $(\|s,%
\|p)$\X\S$\6
$\|k\K\\{hyph\_word}[\|h]$;\6
\&{if} $\\{length}(\|k)<\\{length}(\|s)$ \1\&{then}\5
\&{goto} \37\\{found};\2\6
\&{if} $\\{length}(\|k)>\\{length}(\|s)$ \1\&{then}\5
\&{goto} \37\\{not\_found};\2\6
$\|u\K\\{str\_start}[\|k]$;\5
$\|v\K\\{str\_start}[\|s]$;\6
\1\&{repeat} \37\&{if} $\\{str\_pool}[\|u]<\\{str\_pool}[\|v]$ \1\&{then}\5
\&{goto} \37\\{found};\2\6
\&{if} $\\{str\_pool}[\|u]>\\{str\_pool}[\|v]$ \1\&{then}\5
\&{goto} \37\\{not\_found};\2\6
$\\{incr}(\|u)$;\5
$\\{incr}(\|v)$;\6
\4\&{until}\5
$\|u=\\{str\_start}[\|k+1]$;\2\6
\4\\{found}: \37$\|q\K\\{hyph\_list}[\|h]$;\5
$\\{hyph\_list}[\|h]\K\|p$;\5
$\|p\K\|q$;\6
$\|t\K\\{hyph\_word}[\|h]$;\5
$\\{hyph\_word}[\|h]\K\|s$;\5
$\|s\K\|t$;\6
\4\\{not\_found}: \37\par
\U section~940.\fi

\N942.  \[43] Initializing the hyphenation tables.
The trie for \TeX's hyphenation algorithm is built from a sequence of
patterns following a \.{\\patterns} specification. Such a specification
is allowed only in \.{INITEX}, since the extra memory for auxiliary tables
and for the initialization program itself would only clutter up the
production version of \TeX\ with a lot of deadwood.

The initialization first builds a trie that is linked instead of packed
into sequential storage, so that insertions are readily made. Then it
compresses the linked trie by identifying common subtries, and finally the
trie is packed into the efficient sequential form that the hyphenation
algorithm actually uses.

\Y\P\&{init} \37\X944:Declare procedures for preprocessing hyphenation patterns%
\X\6
\&{tini}\par
\fi

\M943. Before we discuss trie building in detail, let's consider the simpler
problem of creating the \\{hyf\_distance}, \\{hyf\_num}, and \\{hyf\_next}
arrays.

Suppose, for example, that \TeX\ reads the pattern `\.{ab2cde1}'. This is
a pattern of length 5, with $n_0\ldots n_5=0\,0\,2\,0\,0\,1$ in the
notation above. We want the corresponding \\{trie\_op} code \|v to have
$\\{hyf\_distance}[\|v]=3$, $\\{hyf\_num}[\|v]=2$, and $\\{hyf\_next}[\|v]=%
\hbox{$v↑\prime$}$,
where the auxiliary \\{trie\_op} code $v↑\prime$ has
$\\{hyf\_distance}[\hbox{$v↑\prime$}]=0$, $\\{hyf\_num}[\hbox{$v↑\prime$}]=1$,
and
$\\{hyf\_next}[\hbox{$v↑\prime$}]=\\{min\_quarterword}$.

\TeX\ computes an appropriate value \|v with the \\{new\_trie\_op} subroutine
below, by setting
$$\hbox{$\hbox{$v↑\prime$}\K\\{new\_trie\_op}(0,1,\\{min\_quarterword})$,\qquad
$\|v\K\\{new\_trie\_op}(3,2,\hbox{$v↑\prime$})$.}$$
This subroutine looks up its three
parameters in a special hash table, assigning a new value only if these
three have not appeared before.

The hash table is called \\{trie\_op\_hash}, and the number of entries it
contains
is \\{trie\_op\_ptr}. If the table overflows, the excess ops are ignored.

\Y\P\D \37$\\{quarterword\_diff}=\\{max\_quarterword}-\\{min\_quarterword}$\par
\P\D \37$\\{trie\_op\_hash\_size}=\\{quarterword\_diff}+\\{quarterword\_diff}$%
\C{double}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\&{init} \37\\{trie\_op\_hash}: \37\&{array} $[0\to\\{trie\_op\_hash\_size}]$ %
\1\&{of}\5
\\{quarterword};\C{trie op codes for triples}\2\6
\&{tini}\6
\4\hbox{\hskip1em}\\{trie\_op\_ptr}: \37\\{quarterword};\C{highest \\{trie\_op}
assigned}\par
\fi

\M944. The hash function used by \\{new\_trie\_op} is based on the observation
that
313/510 is an approximation to the golden ratio [cf.\ {\sl The Art of
Computer Programming \bf3} (1973), 510--512]; \\{trie\_op\_hash\_size} is
usually a multiple of 510.  But the choice is comparatively unimportant in
this particular application.

\Y\P$\4\X944:Declare procedures for preprocessing hyphenation patterns\X\S$\6
\4\&{function}\1\  \37$\\{new\_trie\_op}(\|d,\39\|n:\\{small\_number};\,\35\|v:%
\\{quarterword})$: \37\\{quarterword};\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37\|h: \37$0\to\\{trie\_op\_hash\_size}$;\C{trial hash location}\6
\|u: \37\\{quarterword};\C{trial op code}\2\6
\&{begin} \37$\|h\K\\{abs}(\|n+313\ast\|d+361\ast\|v)\mathbin{\&{mod}}\\{trie%
\_op\_hash\_size}$;\6
\~ \1\&{loop}\ \&{begin} \37$\|u\K\\{trie\_op\_hash}[\|h]$;\6
\&{if} $\|u=\\{min\_quarterword}$ \1\&{then}\C{empty position found}\6
\&{begin} \37\&{if} $\\{trie\_op\_ptr}=\\{max\_quarterword}$ \1\&{then}%
\C{overflow}\6
\&{begin} \37$\\{new\_trie\_op}\K\\{min\_quarterword}$;\5
\&{return};\6
\&{end};\2\6
$\\{incr}(\\{trie\_op\_ptr})$;\5
$\\{hyf\_distance}[\\{trie\_op\_ptr}]\K\|d$;\5
$\\{hyf\_num}[\\{trie\_op\_ptr}]\K\|n$;\5
$\\{hyf\_next}[\\{trie\_op\_ptr}]\K\|v$;\5
$\\{trie\_op\_hash}[\|h]\K\\{trie\_op\_ptr}$;\5
$\\{new\_trie\_op}\K\\{trie\_op\_ptr}$;\5
\&{return};\6
\&{end};\2\6
\&{if} $(\\{hyf\_distance}[\|u]=\|d)\W(\\{hyf\_num}[\|u]=\|n)\W(\\{hyf\_next}[%
\|u]=\|v)$ \1\&{then}\6
\&{begin} \37$\\{new\_trie\_op}\K\|u$;\5
\&{return};\6
\&{end};\2\6
\&{if} $\|h>0$ \1\&{then}\5
$\\{decr}(\|h)$\ \&{else} $\|h\K\\{trie\_op\_hash\_size}$;\2\6
\&{end};\2\6
\4\\{exit}: \37\&{end};\par
\A sections~947, 948, 949, 951, 953, 957, 959, and~960.
\U section~942.\fi

\M945. The linked trie that is used to preprocess hyphenation patterns appears
in several global arrays. Each node represents an instruction of the form
``if you see character \|c, then perform operation \|o, move to the
next character, and go to node \|l; otherwise go to node \|r.''
The four quantities \|c, \|o, \|l, and \|r are stored in four arrays
\\{trie\_c}, \\{trie\_o}, \\{trie\_l}, and \\{trie\_r}. The root of the trie
is $\\{trie\_l}[0]$, and the number of nodes is \\{trie\_ptr}. Null trie
pointers are represented by zero. To initialize the trie, we simply
set $\\{trie\_l}[0]$ and \\{trie\_ptr} to zero. We also set $\\{trie\_c}[0]$ to
some
arbitrary value, since the algorithm may access it.

The algorithms maintain the condition $\\{trie\_c}[\\{trie\_r}[\|z]]>\\{trie%
\_c}[\|z]$
whenever $\|z\I0$ and $\\{trie\_r}[\|z]\I0$; in other words, sibling nodes are
ordered by their \|c fields.

\Y\P\D \37$\\{trie\_root}\S\\{trie\_l}[0]$\C{root of the linked trie}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\&{init} \37\\{trie\_c}: \37\&{packed} \37\&{array} $[\\{trie\_pointer}]$ \1%
\&{of}\5
\\{ASCII\_code};\C{characters to match}\2\6
\4\hbox{\hskip1em}\\{trie\_o}: \37\&{packed} \37\&{array} $[\\{trie\_pointer}]$
\1\&{of}\5
\\{quarterword};\C{operations to perform}\2\6
\4\hbox{\hskip1em}\\{trie\_l}: \37\&{packed} \37\&{array} $[\\{trie\_pointer}]$
\1\&{of}\5
\\{trie\_pointer};\C{left subtrie links}\2\6
\4\hbox{\hskip1em}\\{trie\_r}: \37\&{packed} \37\&{array} $[\\{trie\_pointer}]$
\1\&{of}\5
\\{trie\_pointer};\C{right subtrie links}\2\6
\4\hbox{\hskip1em}\\{trie\_ptr}: \37\\{trie\_pointer};\C{the number of nodes in
the trie}\6
\&{tini}\par
\fi

\M946. Let us suppose that a linked trie has already been constructed.
Experience shows that we can often reduce its size by recognizing common
subtries; therefore another hash table is introduced for this purpose,
somewhat similar to \\{trie\_op\_hash}. The new hash table will be
initialized to zero.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\&{init} \37\\{trie\_hash}: \37\&{packed} \37\&{array} $[\\{trie\_pointer}]$ \1%
\&{of}\5
\\{trie\_pointer};\2\6
\&{tini}\C{to identify equivalent subtries}\par
\fi

\M947. The function $\\{trie\_node}(\|p)$ returns \|p if \|p is distinct from
other nodes
that it has seen, otherwise it returns the number of the first equivalent
node that it has seen.

\Y\P$\4\X944:Declare procedures for preprocessing hyphenation patterns\X%
\mathrel{+}\S$\6
\4\&{function}\1\  \37$\\{trie\_node}(\|p:\\{trie\_pointer})$: \37\\{trie%
\_pointer};\C{converts 	to a canonical form}\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37\|h: \37\\{trie\_pointer};\C{trial hash location}\6
\|q: \37\\{trie\_pointer};\C{trial trie node}\2\6
\&{begin} \37$\|h\K\\{abs}(\\{trie\_c}[\|p]+1009\ast\\{trie\_o}[\|p]+\302718%
\ast\\{trie\_l}[\|p]+3142\ast\\{trie\_r}[\|p])\mathbin{\&{mod}}\\{trie\_size}$;%
\6
\~ \1\&{loop}\ \&{begin} \37$\|q\K\\{trie\_hash}[\|h]$;\6
\&{if} $\|q=0$ \1\&{then}\6
\&{begin} \37$\\{trie\_hash}[\|h]\K\|p$;\5
$\\{trie\_node}\K\|p$;\5
\&{return};\6
\&{end};\2\6
\&{if} $(\\{trie\_c}[\|q]=\\{trie\_c}[\|p])\W(\\{trie\_o}[\|q]=\\{trie\_o}[%
\|p])\W\30(\\{trie\_l}[\|q]=\\{trie\_l}[\|p])\W(\\{trie\_r}[\|q]=\\{trie\_r}[%
\|p])$ \1\&{then}\6
\&{begin} \37$\\{trie\_node}\K\|q$;\5
\&{return};\6
\&{end};\2\6
\&{if} $\|h>0$ \1\&{then}\5
$\\{decr}(\|h)$\ \&{else} $\|h\K\\{trie\_size}$;\2\6
\&{end};\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M948. A neat recursive procedure is now able to compress a trie by
traversing it and applying \\{trie\_node} to its nodes in ``bottom up''
fashion. We will compress the entire trie by clearing \\{trie\_hash} to
zero and then saying `$\\{trie\_root}\K\\{compress\_trie}(\\{trie\_root})$'.

\Y\P$\4\X944:Declare procedures for preprocessing hyphenation patterns\X%
\mathrel{+}\S$\6
\4\&{function}\1\  \37$\\{compress\_trie}(\|p:\\{trie\_pointer})$: \37\\{trie%
\_pointer};\2\6
\&{begin} \37\&{if} $\|p=0$ \1\&{then}\5
$\\{compress\_trie}\K0$\6
\4\&{else} \&{begin} \37$\\{trie\_l}[\|p]\K\\{compress\_trie}(\\{trie\_l}[%
\|p])$;\5
$\\{trie\_r}[\|p]\K\\{compress\_trie}(\\{trie\_r}[\|p])$;\5
$\\{compress\_trie}\K\\{trie\_node}(\|p)$;\6
\&{end};\2\6
\&{end};\par
\fi

\M949. Before we forget how to initialize the data structures that have been
mentioned so far, let's write a procedure that does the initialization.

\Y\P$\4\X944:Declare procedures for preprocessing hyphenation patterns\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{init\_pattern\_memory};\C{gets ready to build a
linked trie}\6
\4\&{var} \37\|h: \37$0\to\\{trie\_op\_hash\_size}$;\C{an index into \\{trie%
\_op\_hash}}\6
\|p: \37\\{trie\_pointer};\C{an index into \\{trie\_hash}}\2\6
\&{begin} \37\&{for} $\|h\K0\mathrel{\&{to}}\\{trie\_op\_hash\_size}$ \1\&{do}\5
$\\{trie\_op\_hash}[\|h]\K\\{min\_quarterword}$;\2\6
$\\{trie\_op\_ptr}\K\\{min\_quarterword}$;\5
$\\{trie\_root}\K0$;\5
$\\{trie\_c}[0]\K0$;\5
$\\{trie\_ptr}\K0$;\6
\&{for} $\|p\K0\mathrel{\&{to}}\\{trie\_size}$ \1\&{do}\5
$\\{trie\_hash}[\|p]\K0$;\2\6
\&{end};\par
\fi

\M950. The compressed trie will be packed into the \\{trie} array using a
``top-down first-fit'' procedure. This is a little tricky, so the reader
should pay close attention: The \\{trie\_hash} array is cleared to zero
again and renamed \\{trie\_ref} for this phase of the operation; later on,
$\\{trie\_ref}[\|p]$ will be nonzero if the linked trie node \|p is the oldest
sibling
in a family and if the characters \|c of that family have been allocated to
locations $\\{trie\_ref}[\|p]+\|c$ in the \\{trie} array. Locations of \\{trie}
that
are in use will have $\\{trie\_link}=0$, while the unused holes in \\{trie}
will be doubly linked with \\{trie\_link} pointing to the next larger vacant
location and \\{trie\_back} pointing to the next smaller one. This double
linking will have been carried out only as far as \\{trie\_max}, where
\\{trie\_max} is the largest index of \\{trie} that will be needed.
Another array \\{trie\_taken} tells whether or not a given location is
equal to $\\{trie\_ref}[\|p]$ for some \|p; this array is used to ensure that
distinct nodes in the compressed trie will have distinct \\{trie\_ref}
entries.

\Y\P\D \37$\\{trie\_ref}\S\\{trie\_hash}$\C{where linked trie families go into %
\\{trie}}\par
\P\D \37$\\{trie\_back}(\#)\S\\{trie}[\#].\\{lh}$\C{backward links in \\{trie}
holes}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\&{init} \37\\{trie\_taken}: \37\&{packed} \37\&{array} $[\\{trie\_pointer}]$ %
\1\&{of}\5
\\{boolean};\C{does a family start here?}\2\6
\4\hbox{\hskip1em}\\{trie\_min}: \37\\{trie\_pointer};\C{all locations $\L%
\\{trie\_min}$ are vacant in \\{trie}}\6
\&{tini}\6
\4\hbox{\hskip1em}\\{trie\_max}: \37\\{trie\_pointer};\C{largest location used
in \\{trie}}\par
\fi

\M951. Here is how these data structures are initialized.

\Y\P$\4\X944:Declare procedures for preprocessing hyphenation patterns\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{init\_trie\_memory};\C{gets ready to pack into %
\\{trie}}\6
\4\&{var} \37\|p: \37\\{trie\_pointer};\C{index into \\{trie\_ref}, \\{trie}, %
\\{trie\_taken}}\2\6
\&{begin} \37\&{for} $\|p\K0\mathrel{\&{to}}\\{trie\_ptr}$ \1\&{do}\5
$\\{trie\_ref}[\|p]\K0$;\2\6
$\\{trie\_max}\K128$;\5
$\\{trie\_min}\K128$;\5
$\\{trie\_link}(0)\K1$;\5
$\\{trie\_taken}[0]\K\\{false}$;\6
\&{for} $\|p\K1\mathrel{\&{to}}128$ \1\&{do}\6
\&{begin} \37$\\{trie\_back}(\|p)\K\|p-1$;\5
$\\{trie\_link}(\|p)\K\|p+1$;\5
$\\{trie\_taken}[\|p]\K\\{false}$;\6
\&{end};\2\6
\&{end};\par
\fi

\M952. Each time \.{\\patterns} appears, it overrides any patterns that were
entered earlier, so the arrays are not initialized until \TeX\ sees
\.{\\patterns}. However, some of the global variables must be
initialized when \.{INITEX} is loaded, in case the user never mentions
any \.{\\patterns}.

\Y\P$\4\X164:Initialize table entries (done by \.{INITEX} only)\X\mathrel{+}\S$%
\6
$\\{trie\_op\_ptr}\K\\{min\_quarterword}$;\6
$\\{trie\_link}(0)\K0$;\5
$\\{trie\_char}(0)\K0$;\5
$\\{trie\_op}(0)\K0$;\6
\&{for} $\|k\K1\mathrel{\&{to}}127$ \1\&{do}\5
$\\{trie}[\|k]\K\\{trie}[0]$;\2\6
$\\{trie\_max}\K127$;\par
\fi

\M953. The \\{first\_fit} procedure finds the smallest hole \|z in \\{trie}
such that
a trie family starting at a given node \|p will fit into vacant positions
starting at \|z. If $\|c=\\{trie\_c}[\|p]$, this means that location $\|z-\|c$
must
not already be taken by some other family, and that $\|z-\|c+\hbox{$c↑\prime$}$
must be vacant for all characters $c↑\prime$ in the family. The procedure
sets $\\{trie\_ref}[\|p]$ to $\|z-\|c$ when the first fit has been found.

\Y\P$\4\X944:Declare procedures for preprocessing hyphenation patterns\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{first\_fit}(\|p:\\{trie\_pointer})$;\C{packs a
family into \\{trie}}\6
\4\&{label} \37$\\{not\_found},\39\\{found}$;\6
\4\&{var} \37\|h: \37\\{trie\_pointer};\C{candidate for $\\{trie\_ref}[\|p]$}\6
\|z: \37\\{trie\_pointer};\C{runs through holes}\6
\|q: \37\\{trie\_pointer};\C{runs through the family starting at \|p}\6
\|c: \37\\{ASCII\_code};\C{smallest character in the family}\2\6
\&{begin} \37$\|c\K\\{trie\_c}[\|p]$;\C{we have $\|c>0$}\6
\&{if} $\|c<\\{trie\_min}$ \1\&{then}\5
$\\{trie\_min}\K\|c$;\2\6
$\|z\K\\{trie\_link}(\\{trie\_min}-1)$;\C{get the first conceivably good hole}\6
\~ \1\&{loop}\ \&{begin} \37\&{if} $\|z<\|c$ \1\&{then}\5
\&{goto} \37\\{not\_found};\2\6
$\|h\K\|z-\|c$;\6
\X954:Ensure that $\\{trie\_max}\G\|h+128$\X;\6
\&{if} $\\{trie\_taken}[\|h]$ \1\&{then}\5
\&{goto} \37\\{not\_found};\2\6
\X955:If all characters of the family fit relative to \|h, then \&{goto} %
\\{found},\30\ otherwise \&{goto} \\{not\_found}\X;\6
\4\\{not\_found}: \37$\|z\K\\{trie\_link}(\|z)$;\C{move to the next hole}\6
\&{end};\2\6
\4\\{found}: \37\X956:Pack the family into \\{trie} relative to \|h\X;\6
\&{end};\par
\fi

\M954. By making sure that \\{trie\_max} is at least $\|h+128$, we can be sure
that
$\\{trie\_max}>\|z$, since $\|h=\|z-\|c$. It follows that location \\{trie%
\_max} will
never be occupied in \\{trie}, and we will have $\\{trie\_max}\G\\{trie\_link}(%
\|z)$.

\Y\P$\4\X954:Ensure that $\\{trie\_max}\G\|h+128$\X\S$\6
\&{if} $\\{trie\_max}<\|h+128$ \1\&{then}\6
\&{begin} \37\&{if} $\\{trie\_size}\L\|h+128$ \1\&{then}\5
$\\{overflow}(\.{"pattern\ memory"},\39\\{trie\_size})$;\2\6
\1\&{repeat} \37$\\{incr}(\\{trie\_max})$;\5
$\\{trie\_taken}[\\{trie\_max}]\K\\{false}$;\5
$\\{trie\_link}(\\{trie\_max})\K\\{trie\_max}+1$;\5
$\\{trie\_back}(\\{trie\_max})\K\\{trie\_max}-1$;\6
\4\&{until}\5
$\\{trie\_max}=\|h+128$;\2\6
\&{end}\2\par
\U section~953.\fi

\M955. \P$\X955:If all characters of the family fit relative to \|h, then %
\&{goto} \\{found},\30\ otherwise \&{goto} \\{not\_found}\X\S$\6
$\|q\K\\{trie\_r}[\|p]$;\6
\&{while} $\|q>0$ \1\&{do}\6
\&{begin} \37\&{if} $\\{trie\_link}(\|h+\\{trie\_c}[\|q])=0$ \1\&{then}\5
\&{goto} \37\\{not\_found};\2\6
$\|q\K\\{trie\_r}[\|q]$;\6
\&{end};\2\6
\&{goto} \37\\{found}\par
\U section~953.\fi

\M956. \P$\X956:Pack the family into \\{trie} relative to \|h\X\S$\6
$\\{trie\_taken}[\|h]\K\\{true}$;\5
$\\{trie\_ref}[\|p]\K\|h$;\5
$\|q\K\|p$;\6
\1\&{repeat} \37$\|z\K\|h+\\{trie\_c}[\|q]$;\5
$\\{trie\_back}(\\{trie\_link}(\|z))\K\\{trie\_back}(\|z)$;\5
$\\{trie\_link}(\\{trie\_back}(\|z))\K\\{trie\_link}(\|z)$;\5
$\\{trie\_link}(\|z)\K0$;\5
$\|q\K\\{trie\_r}[\|q]$;\6
\4\&{until}\5
$\|q=0$\2\par
\U section~953.\fi

\M957. To pack the entire linked trie, we use the following recursive
procedure.

\Y\P$\4\X944:Declare procedures for preprocessing hyphenation patterns\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{trie\_pack}(\|p:\\{trie\_pointer})$;\C{pack subtries
of a family}\6
\4\&{var} \37\|q: \37\\{trie\_pointer};\C{a local variable that need not be
saved on recursive calls}\2\6
\&{begin} \37\1\&{repeat} \37$\|q\K\\{trie\_l}[\|p]$;\6
\&{if} $(\|q>0)\W(\\{trie\_ref}[\|q]=0)$ \1\&{then}\6
\&{begin} \37$\\{first\_fit}(\|q)$;\5
$\\{trie\_pack}(\|q)$;\6
\&{end};\2\6
$\|p\K\\{trie\_r}[\|p]$;\6
\4\&{until}\5
$\|p=0$;\2\6
\&{end};\par
\fi

\M958. When the whole trie has been allocated into the sequential table, we
must go through it once again so that \\{trie} contains the correct
information. Null pointers in the linked trie will be replaced by the
first untaken position \|r in \\{trie}, since this properly implements an
``empty'' family. The value of \|r is stored in $\\{trie\_ref}[0]$ just before
the fixup process starts. Note that \\{trie\_max} will always be at least as
large as $\|r+127$, since it is always at least 128 more than each location
that is taken.

\Y\P$\4\X958:Move the data into \\{trie}\X\S$\6
$\|r\K0$;\6
\&{while} $\\{trie\_taken}[\|r]$ \1\&{do}\5
$\\{incr}(\|r)$;\2\6
$\\{trie\_ref}[0]\K\|r$;\C{\|r will be used for null pointers}\6
$\\{trie\_fix}(\\{trie\_root})$\C{this fixes the non-holes in \\{trie}}\par
\U section~966.\fi

\M959. The fixing-up procedure is, of course, recursive. Since the linked trie
usually has overlapping subtries, the same data may be moved several
times; but that causes no harm, and at most as much work is done as it
took to build the uncompressed trie.

\Y\P$\4\X944:Declare procedures for preprocessing hyphenation patterns\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{trie\_fix}(\|p:\\{trie\_pointer})$;\C{moves \|p and
its siblings into \\{trie}}\6
\4\&{var} \37\|q: \37\\{trie\_pointer};\C{a local variable that need not be
saved on recursive calls}\6
\|c: \37\\{ASCII\_code};\C{another one that need not be saved}\6
\|z: \37\\{trie\_pointer};\C{\\{trie} reference; this local variable must be
saved}\2\6
\&{begin} \37$\|z\K\\{trie\_ref}[\|p]$;\6
\&{while} $\|p\I0$ \1\&{do}\6
\&{begin} \37$\|q\K\\{trie\_l}[\|p]$;\5
$\|c\K\\{trie\_c}[\|p]$;\5
$\\{trie\_link}(\|z+\|c)\K\\{trie\_ref}[\|q]$;\5
$\\{trie\_char}(\|z+\|c)\K\|c$;\5
$\\{trie\_op}(\|z+\|c)\K\\{trie\_o}[\|p]$;\6
\&{if} $\|q>0$ \1\&{then}\5
$\\{trie\_fix}(\|q)$;\2\6
$\|p\K\\{trie\_r}[\|p]$;\6
\&{end};\2\6
\&{end};\par
\fi

\M960. Now let's put all these routines together. When \.{INITEX} has scanned
the `\.{\\patterns}' control sequence, it calls on \\{new\_patterns} to do
the right thing. After \\{new\_patterns} has acted, the compacted pattern data
will appear in the array $\\{trie}[1\to\\{trie\_max}]$, and the associated
numeric
hyphenation data will appear in locations $[(\\{min\_quarterword}+1)\to\\{trie%
\_op\_ptr}]$
of the arrays \\{hyf\_distance}, \\{hyf\_num}, \\{hyf\_next}.

\Y\P$\4\X944:Declare procedures for preprocessing hyphenation patterns\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{new\_patterns};\C{initializes the hyphenation pattern
data}\6
\4\&{label} \37$\\{done},\39\\{done1}$;\6
\4\&{var} \37$\|k,\39\|l$: \37\\{small\_number};\C{indices into \\{hc} and %
\\{hyf}}\6
\\{digit\_sensed}: \37\\{boolean};\C{should the next digit be treated as a
letter?}\6
\|v: \37\\{quarterword};\C{trie op code}\6
$\|p,\39\|q$: \37\\{trie\_pointer};\C{nodes of trie traversed during insertion}%
\6
\\{first\_child}: \37\\{boolean};\C{is $\|p=\\{trie\_l}[\|q]$?}\6
\|c: \37\\{ASCII\_code};\C{character being inserted}\6
$\|r,\39\|s$: \37\\{trie\_pointer};\C{used to clean up the packed \\{trie}}\6
\|h: \37\\{two\_halves};\C{template used to zero out \\{trie}'s holes}\2\6
\&{begin} \37\\{scan\_left\_brace};\C{a left brace must follow \.{\\patterns}}\6
\\{init\_pattern\_memory};\6
\X961:Enter all of the patterns into a linked trie, until coming to a right
brace; then skip an optional space\X;\6
$\\{trie\_root}\K\\{compress\_trie}(\\{trie\_root})$;\C{compress the trie}\6
\X966:Pack the trie\X;\6
\&{end};\par
\fi

\M961. Novices are not supposed to be using \.{\\patterns}, so the error
messages are terse. (Note that all error messages appear in \TeX's string
pool, even if they are used only by \.{INITEX}.)

\Y\P$\4\X961:Enter all of the patterns into a linked trie, until coming to a
right brace; then skip an optional space\X\S$\6
$\|k\K0$;\5
$\\{hyf}[0]\K0$;\5
$\\{digit\_sensed}\K\\{false}$;\6
\~ \1\&{loop}\ \&{begin} \37\\{get\_x\_token};\6
\&{case} $\\{cur\_cmd}$ \1\&{of}\6
\4$\\{letter},\39\\{other\_char}$: \37\X962:Append a new letter or a hyphen
level\X;\6
\4$\\{spacer},\39\\{right\_brace}$: \37\&{begin} \37\&{if} $\|k>0$ \1\&{then}\5
\X963:Insert a new pattern into the linked trie\X;\2\6
\&{if} $\\{cur\_cmd}=\\{right\_brace}$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
$\|k\K0$;\5
$\\{hyf}[0]\K0$;\5
$\\{digit\_sensed}\K\\{false}$;\6
\&{end};\6
\4\&{othercases} \37\&{begin} \37$\\{print\_err}(\.{"Bad\ "})$;\5
$\\{print\_esc}(\.{"patterns"})$;\5
$\\{help1}(\.{"(See\ Appendix\ H.)"})$;\5
\\{error};\6
\&{end}\2\6
\&{endcases};\6
\&{end};\2\6
\4\\{done}: \37\par
\U section~960.\fi

\M962. \P$\X962:Append a new letter or a hyphen level\X\S$\6
\&{if} $\\{digit\_sensed}\V(\\{cur\_chr}<\.{"0"})\V(\\{cur\_chr}>\.{"9"})$ \1%
\&{then}\6
\&{begin} \37\&{if} $\\{cur\_chr}=\.{"."}$ \1\&{then}\5
$\\{cur\_chr}\K128$\C{edge-of-word delimiter}\6
\4\&{else} \&{begin} \37$\\{cur\_chr}\K\\{lc\_code}(\\{cur\_chr})$;\6
\&{if} $\\{cur\_chr}=0$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Nonletter"})$;\5
$\\{help1}(\.{"(See\ Appendix\ H.)"})$;\5
\\{error};\5
$\\{cur\_chr}\K128$;\6
\&{end};\2\6
\&{end};\2\6
\&{if} $\|k<63$ \1\&{then}\6
\&{begin} \37$\\{incr}(\|k)$;\5
$\\{hc}[\|k]\K\\{cur\_chr}-1$;\5
$\\{hyf}[\|k]\K0$;\5
$\\{digit\_sensed}\K\\{false}$;\6
\&{end};\2\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{hyf}[\|k]\K\\{cur\_chr}-\.{"0"}$;\6
\&{if} $\|k<63$ \1\&{then}\5
$\\{digit\_sensed}\K\\{true}$;\2\6
\&{end}\2\par
\U section~961.\fi

\M963. When the following code comes into play, the pattern $p_1\ldots p_k$
appears in $\\{hc}[1\to\|k]$, and the corresponding sequence of numbers $n_0%
\ldots
n_k$ appears in $\\{hyf}[0\to\|k]$.

\Y\P$\4\X963:Insert a new pattern into the linked trie\X\S$\6
\&{begin} \37\X965:Compute the trie op code, \|v, and set $\|l\K0$\X;\6
$\|q\K0$;\6
\&{while} $\|l<\|k$ \1\&{do}\6
\&{begin} \37$\\{incr}(\|l)$;\5
$\|c\K\\{hc}[\|l]$;\5
$\|p\K\\{trie\_l}[\|q]$;\5
$\\{first\_child}\K\\{true}$;\6
\&{while} $(\|p>0)\W(\|c>\\{trie\_c}[\|p])$ \1\&{do}\6
\&{begin} \37$\|q\K\|p$;\5
$\|p\K\\{trie\_r}[\|q]$;\5
$\\{first\_child}\K\\{false}$;\6
\&{end};\2\6
\&{if} $(\|p=0)\V(\|c<\\{trie\_c}[\|p])$ \1\&{then}\5
\X964:Insert a new trie node between \|q and \|p, and make \|p point to it\X;\2%
\6
$\|q\K\|p$;\C{now node \|q represents $p_1\ldots p_l$}\6
\&{end};\2\6
\&{if} $\\{trie\_o}[\|q]\I\\{min\_quarterword}$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Duplicate\ pattern"})$;\5
$\\{help1}(\.{"(See\ Appendix\ H.)"})$;\5
\\{error};\6
\&{end};\2\6
$\\{trie\_o}[\|q]\K\|v$;\6
\&{end}\par
\U section~961.\fi

\M964. \P$\X964:Insert a new trie node between \|q and \|p, and make \|p point
to it\X\S$\6
\&{begin} \37\&{if} $\\{trie\_ptr}=\\{trie\_size}$ \1\&{then}\5
$\\{overflow}(\.{"pattern\ memory"},\39\\{trie\_size})$;\2\6
$\\{incr}(\\{trie\_ptr})$;\5
$\\{trie\_r}[\\{trie\_ptr}]\K\|p$;\5
$\|p\K\\{trie\_ptr}$;\5
$\\{trie\_l}[\|p]\K0$;\6
\&{if} $\\{first\_child}$ \1\&{then}\5
$\\{trie\_l}[\|q]\K\|p$\ \&{else} $\\{trie\_r}[\|q]\K\|p$;\2\6
$\\{trie\_c}[\|p]\K\|c$;\5
$\\{trie\_o}[\|p]\K\\{min\_quarterword}$;\6
\&{end}\par
\U section~963.\fi

\M965. \P$\X965:Compute the trie op code, \|v, and set $\|l\K0$\X\S$\6
\&{if} $\\{hc}[1]=127$ \1\&{then}\5
$\\{hyf}[0]\K0$;\2\6
\&{if} $\\{hc}[\|k]=127$ \1\&{then}\5
$\\{hyf}[\|k]\K0$;\2\6
$\|l\K\|k$;\5
$\|v\K\\{min\_quarterword}$;\6
\~ \1\&{loop}\ \&{begin} \37\&{if} $\\{hyf}[\|l]\I0$ \1\&{then}\5
$\|v\K\\{new\_trie\_op}(\|k-\|l,\39\\{hyf}[\|l],\39\|v)$;\2\6
\&{if} $\|l>0$ \1\&{then}\5
$\\{decr}(\|l)$\ \&{else} \&{goto} \37\\{done1};\2\6
\&{end};\2\6
\4\\{done1}: \37\par
\U section~963.\fi

\M966. The following packing routine is rigged so that the root of the linked
tree gets mapped into location 0 of \\{trie}, as required by the hyphenation
algorithm. This happens because the first call of \\{first\_fit} will
``take'' location~0.

\Y\P$\4\X966:Pack the trie\X\S$\6
\\{init\_trie\_memory};\6
\&{if} $\\{trie\_root}\I0$ \1\&{then}\6
\&{begin} \37$\\{first\_fit}(\\{trie\_root})$;\5
$\\{trie\_pack}(\\{trie\_root})$;\6
\&{end};\2\6
\X958:Move the data into \\{trie}\X;\6
$\|r\K0$;\C{finally, we will zero out the holes}\6
$\|h.\\{rh}\K0$;\5
$\|h.\\{b0}\K\\{min\_quarterword}$;\5
$\|h.\\{b1}\K0$;\C{$\\{trie\_link}\K0$, 	$\\{trie\_op}\K\\{min\_quarterword}$,
$\\{trie\_char}\K0$}\6
\1\&{repeat} \37$\|s\K\\{trie\_link}(\|r)$;\5
$\\{trie}[\|r]\K\|h$;\5
$\|r\K\|s$;\6
\4\&{until}\5
$\|r>\\{trie\_max}$\2\par
\U section~960.\fi

\N967.  \[44] Breaking vertical lists into pages.
The \\{vsplit} procedure, which implements \TeX's \.{\\vsplit} operation,
is considerably simpler than \\{line\_break} because it doesn't have to
worry about hyphenation, and because its mission is to discover a single
break instead of an optimum sequence of breakpoints.  But before we get
into the details of \\{vsplit}, we need to consider a few more basic things.

\fi

\M968. A subroutine called \\{prune\_page\_top} takes a pointer to a vlist and
returns a pointer to a modified vlist in which all glue, kern, and penalty
nodes
have been deleted before the first box or rule node. However, the first
box or rule is actually preceded by a newly created glue node designed so that
the topmost baseline will be at distance \\{split\_top\_skip} from the top,
whenever this is possible without backspacing.

In this routine and those that follow, we make use of the fact that a
vertical list contains no character nodes, hence the \\{type} field exists
for each node in the list.

\Y\P\4\&{function}\1\  \37$\\{prune\_page\_top}(\|p:\\{pointer})$: \37%
\\{pointer};\C{adjust top after page break}\6
\4\&{var} \37\\{prev\_p}: \37\\{pointer};\C{lags one step behind \|p}\6
\|q: \37\\{pointer};\C{temporary variable for list manipulation}\2\6
\&{begin} \37$\\{prev\_p}\K\\{temp\_head}$;\5
$\\{link}(\\{temp\_head})\K\|p$;\6
\&{while} $\|p\I\\{null}$ \1\&{do}\6
\&{case} $\\{type}(\|p)$ \1\&{of}\6
\4$\\{hlist\_node},\39\\{vlist\_node},\39\\{rule\_node}$: \37\X969:Insert glue
for \\{split\_top\_skip} and set~$\|p\K\\{null}$\X;\6
\4$\\{whatsit\_node},\39\\{mark\_node},\39\\{ins\_node}$: \37\&{begin} \37$%
\\{prev\_p}\K\|p$;\5
$\|p\K\\{link}(\\{prev\_p})$;\6
\&{end};\6
\4$\\{glue\_node},\39\\{kern\_node},\39\\{penalty\_node}$: \37\&{begin} \37$\|q%
\K\|p$;\5
$\|p\K\\{link}(\|q)$;\5
$\\{link}(\|q)\K\\{null}$;\5
$\\{link}(\\{prev\_p})\K\|p$;\5
$\\{flush\_node\_list}(\|q)$;\6
\&{end};\6
\4\&{othercases} \37$\\{confusion}(\.{"pruning"})$\2\6
\&{endcases};\2\6
$\\{prune\_page\_top}\K\\{link}(\\{temp\_head})$;\6
\&{end};\par
\fi

\M969. \P$\X969:Insert glue for \\{split\_top\_skip} and set~$\|p\K\\{null}$\X%
\S$\6
\&{begin} \37$\|q\K\\{new\_skip\_param}(\\{split\_top\_skip\_code})$;\5
$\\{link}(\\{prev\_p})\K\|q$;\5
$\\{link}(\|q)\K\|p$;\C{now $\\{temp\_ptr}=\\{glue\_ptr}(\|q)$}\6
\&{if} $\\{width}(\\{temp\_ptr})>\\{height}(\|p)$ \1\&{then}\5
$\\{width}(\\{temp\_ptr})\K\\{width}(\\{temp\_ptr})-\\{height}(\|p)$\6
\4\&{else} $\\{width}(\\{temp\_ptr})\K0$;\2\6
$\|p\K\\{null}$;\6
\&{end}\par
\U section~968.\fi

\M970. The next subroutine finds the best place to break a given vertical list
so as to obtain a box of height~\|h, with maximum depth~\|d.
A pointer to the beginning of the vertical list is given,
and a pointer to the optimum breakpoint is returned. The list is effectively
followed by a forced break, i.e., a penalty node with the \\{eject\_penalty};
if the best break occurs at this artificial node, the value \\{null} is
returned.

An array of six \\{scaled} distances is used to keep track of the height
from the beginning of the list to the current place, just as in \\{line%
\_break}.
In fact, we use one of the same arrays, only changing its name to reflect
its new significance.

\Y\P\D \37$\\{active\_height}\S\\{active\_width}$\C{new name for the six
distance variables}\par
\P\D \37$\\{cur\_height}\S\\{active\_height}[1]$\C{the natural height}\par
\P\D \37$\\{set\_height\_zero}(\#)\S\\{active\_height}[\#]\K0$\C{initialize the
height to zero}\Y\par
\P\D \37$\\{update\_heights}=90$\C{go here to record glue in the \\{active%
\_height} table}\par
\Y\P\4\&{function}\1\  \37$\\{vert\_break}(\|p:\\{pointer};\,\35\|h,\39\|d:%
\\{scaled})$: \37\\{pointer};\C{finds optimum page break}\6
\4\&{label} \37$\\{done},\39\\{not\_found},\39\\{update\_heights}$;\6
\4\&{var} \37\\{prev\_p}: \37\\{pointer};\C{if \|p is a glue node, $\\{type}(%
\\{prev\_p})$ determines 	whether \|p is a legal breakpoint}\6
$\|q,\39\|r$: \37\\{pointer};\C{glue specifications}\6
\\{pi}: \37\\{integer};\C{penalty value}\6
\|b: \37\\{integer};\C{badness at a trial breakpoint}\6
\\{least\_cost}: \37\\{integer};\C{the smallest badness plus penalties found so
far}\6
\\{best\_place}: \37\\{pointer};\C{the most recent break that leads to \\{least%
\_cost}}\6
\\{prev\_dp}: \37\\{scaled};\C{depth of previous box in the list}\6
\|t: \37\\{small\_number};\C{\\{type} of the node following a kern}\2\6
\&{begin} \37$\\{prev\_p}\K\|p$;\C{an initial glue node is not a legal
breakpoint}\6
$\\{least\_cost}\K\\{awful\_bad}$;\5
$\\{do\_all\_six}(\\{set\_height\_zero})$;\5
$\\{prev\_dp}\K0$;\6
\~ \1\&{loop}\ \&{begin} \37\X972:If node \|p is a legal breakpoint, check if
this break is the best known, and \&{goto} \\{done} if \|p is null or if the
page-so-far is already too full to accept more stuff\X;\6
$\\{prev\_p}\K\|p$;\5
$\|p\K\\{link}(\\{prev\_p})$;\6
\&{end};\2\6
\4\\{done}: \37$\\{vert\_break}\K\\{best\_place}$;\6
\&{end};\par
\fi

\M971. A global variable \\{best\_height\_plus\_depth} will be set to the
natural size
of the box that corresponds to the optimum breakpoint found by \\{vert\_break}.
(This value is used by the insertion-splitting algorithm of the page builder.)

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{best\_height\_plus\_depth}: \37\\{scaled};\C{height of the best box,
without stretching or 	shrinking}\par
\fi

\M972. A subtle point to be noted here is that the maximum depth~\|d might be
negative, so \\{cur\_height} and \\{prev\_dp} might need to be corrected even
after a glue or kern node.

\Y\P$\4\X972:If node \|p is a legal breakpoint, check if this break is the best
known, and \&{goto} \\{done} if \|p is null or if the page-so-far is already
too full to accept more stuff\X\S$\6
\&{if} $\|p=\\{null}$ \1\&{then}\5
$\\{pi}\K\\{eject\_penalty}$\6
\4\&{else} \X973:Use node \|p to update the current height and depth
measurements; if this node is not a legal breakpoint, \&{goto} \\{not\_found}
or \\{update\_heights}, otherwise set \\{pi} to the associated penalty at the
break\X;\2\6
\X974:Check if node \|p is a new champion breakpoint; then \(go)\&{goto} %
\\{done} if \|p is a forced break or if the page-so-far is already too full\X;\6
\&{if} $(\\{type}(\|p)<\\{glue\_node})\V(\\{type}(\|p)>\\{kern\_node})$ \1%
\&{then}\5
\&{goto} \37\\{not\_found};\2\6
\4\\{update\_heights}: \37\X976:Update the current height and depth
measurements with respect to a glue or kern node~\|p\X;\6
\4\\{not\_found}: \37\&{if} $\\{prev\_dp}>\|d$ \1\&{then}\6
\&{begin} \37$\\{cur\_height}\K\\{cur\_height}+\\{prev\_dp}-\|d$;\5
$\\{prev\_dp}\K\|d$;\6
\&{end};\2\par
\U section~970.\fi

\M973. \P$\X973:Use node \|p to update the current height and depth
measurements; if this node is not a legal breakpoint, \&{goto} \\{not\_found}
or \\{update\_heights}, otherwise set \\{pi} to the associated penalty at the
break\X\S$\6
\&{case} $\\{type}(\|p)$ \1\&{of}\6
\4$\\{hlist\_node},\39\\{vlist\_node},\39\\{rule\_node}$: \37\&{begin} \37%
\hbox{}\6
$\\{cur\_height}\K\\{cur\_height}+\\{prev\_dp}+\\{height}(\|p)$;\5
$\\{prev\_dp}\K\\{depth}(\|p)$;\5
\&{goto} \37\\{not\_found};\6
\&{end};\6
\4\\{whatsit\_node}: \37\X1364:Process whatsit \|p in \\{vert\_break} loop, %
\&{goto} \\{not\_found}\X;\6
\4\\{glue\_node}: \37\&{if} $\\{precedes\_break}(\\{prev\_p})$ \1\&{then}\5
$\\{pi}\K0$\6
\4\&{else} \&{goto} \37\\{update\_heights};\2\6
\4\\{kern\_node}: \37\&{begin} \37\&{if} $\\{link}(\|p)=\\{null}$ \1\&{then}\5
$\|t\K\\{penalty\_node}$\6
\4\&{else} $\|t\K\\{type}(\\{link}(\|p))$;\2\6
\&{if} $\|t=\\{glue\_node}$ \1\&{then}\5
$\\{pi}\K0$\ \&{else} \&{goto} \37\\{update\_heights};\2\6
\&{end};\6
\4\\{penalty\_node}: \37$\\{pi}\K\\{penalty}(\|p)$;\6
\4$\\{mark\_node},\39\\{ins\_node}$: \37\&{goto} \37\\{not\_found};\6
\4\&{othercases} \37$\\{confusion}(\.{"vertbreak"})$\2\6
\&{endcases}\par
\U section~972.\fi

\M974. \P\D \37$\\{deplorable}\S100000$\C{more than \\{inf\_bad}, but less than
\\{awful\_bad}}\par
\Y\P$\4\X974:Check if node \|p is a new champion breakpoint; then \(go)\&{goto}
\\{done} if \|p is a forced break or if the page-so-far is already too full\X%
\S$\6
\&{if} $\\{pi}<\\{inf\_penalty}$ \1\&{then}\6
\&{begin} \37\X975:Compute the badness, \|b, using \\{awful\_bad} if the box is
too full\X;\6
\&{if} $\|b<\\{awful\_bad}$ \1\&{then}\6
\&{if} $\\{pi}\L\\{eject\_penalty}$ \1\&{then}\5
$\|b\K\\{pi}$\6
\4\&{else} \&{if} $\|b<\\{inf\_bad}$ \1\&{then}\5
$\|b\K\|b+\\{pi}$\6
\4\&{else} $\|b\K\\{deplorable}$;\2\2\2\6
\&{if} $\|b\L\\{least\_cost}$ \1\&{then}\6
\&{begin} \37$\\{best\_place}\K\|p$;\5
$\\{least\_cost}\K\|b$;\5
$\\{best\_height\_plus\_depth}\K\\{cur\_height}+\\{prev\_dp}$;\6
\&{end};\2\6
\&{if} $(\|b=\\{awful\_bad})\V(\\{pi}\L\\{eject\_penalty})$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
\&{end}\2\par
\U section~972.\fi

\M975. \P$\X975:Compute the badness, \|b, using \\{awful\_bad} if the box is
too full\X\S$\6
\&{if} $\\{cur\_height}<\|h$ \1\&{then}\6
\&{if} $(\\{active\_height}[3]\I0)\V(\\{active\_height}[4]\I0)\V(\\{active%
\_height}[5]\I0)$ \1\&{then}\5
$\|b\K0$\6
\4\&{else} $\|b\K\\{badness}(\|h-\\{cur\_height},\39\\{active\_height}[2])$\2\6
\4\&{else} \&{if} $\\{cur\_height}-\|h>\\{active\_height}[6]$ \1\&{then}\5
$\|b\K\\{awful\_bad}$\6
\4\&{else} $\|b\K\\{badness}(\\{cur\_height}-\|h,\39\\{active\_height}[6])$\2\2%
\par
\U section~974.\fi

\M976. Vertical lists that are subject to the \\{vert\_break} procedure should
not
contain infinite shrinkability, since that would permit any amount of
information to ``fit'' on one page.

\Y\P$\4\X976:Update the current height and depth measurements with respect to a
glue or kern node~\|p\X\S$\6
\&{if} $\\{type}(\|p)=\\{kern\_node}$ \1\&{then}\5
$\|q\K\|p$\6
\4\&{else} \&{begin} \37$\|q\K\\{glue\_ptr}(\|p)$;\5
$\\{active\_height}[2+\\{stretch\_order}(\|q)]\K\30\\{active\_height}[2+%
\\{stretch\_order}(\|q)]+\\{stretch}(\|q)$;\6
$\\{active\_height}[6]\K\\{active\_height}[6]+\\{shrink}(\|q)$;\6
\&{if} $(\\{shrink\_order}(\|q)\I\\{normal})\W(\\{shrink}(\|q)\I0)$ \1\&{then}\6
\&{begin} \37\hbox{}\6
$\\{print\_err}(\.{"Infinite\ glue\ shrinkage\ found\ in\ box\ being\
split"})$;\6
$\\{help4}(\.{"The\ box\ you\ are\ \\vsplitting\ contains\ some\ infinitely"})$%
\6
$(\.{"shrinkable\ glue,\ e.g.,\ \`\\vss\'\ or\ \`\\vskip\ 0pt\ minus\ 1fil%
\'."})$\6
$(\.{"Such\ glue\ doesn\'t\ belong\ there;\ but\ you\ can\ safely\ proceed,"})$%
\6
$(\.{"since\ the\ offensive\ shrinkability\ has\ been\ made\ finite."})$;\5
\\{error};\5
$\|r\K\\{new\_spec}(\|q)$;\5
$\\{shrink\_order}(\|r)\K\\{normal}$;\5
$\\{delete\_glue\_ref}(\|q)$;\5
$\\{glue\_ptr}(\|p)\K\|r$;\6
\&{end};\2\6
\&{end};\2\6
$\\{cur\_height}\K\\{cur\_height}+\\{prev\_dp}+\\{width}(\|q)$;\5
$\\{prev\_dp}\K0$\par
\U section~972.\fi

\M977. Now we are ready to consider \\{vsplit} itself. Most of
its work is accomplished by the two subroutines that we have just considered.

Given the number of a vlist box \|n, and given a desired page height \|h,
the \\{vsplit} function finds the best initial segment of the vlist and
returns a box for a page of height~\|h. The remainder of the vlist, if
any, replaces the original box, after removing glue and penalties and
adjusting for \\{split\_top\_skip}. Mark nodes in the split-off box are used to
set the values of \\{split\_first\_mark} and \\{split\_bot\_mark}; we use the
fact that $\\{split\_first\_mark}=\\{null}$ if and only if $\\{split\_bot%
\_mark}=\\{null}$.

The original box becomes ``void'' if and only if it has been entirely
extracted.  The extracted box is ``void'' if and only if the original
box was void (or if it was, erroneously, an hlist box).

\Y\P\4\&{function}\1\  \37$\\{vsplit}(\|n:\\{eight\_bits};\,\35\|h:%
\\{scaled})$: \37\\{pointer};\C{extracts a page of height \|h from box \|n}\6
\4\&{label} \37$\\{exit},\39\\{done}$;\6
\4\&{var} \37\|v: \37\\{pointer};\C{the box to be split}\6
\|p: \37\\{pointer};\C{runs through the vlist}\6
\|q: \37\\{pointer};\C{points to where the break occurs}\2\6
\&{begin} \37$\|v\K\\{box}(\|n)$;\6
\&{if} $\\{split\_first\_mark}\I\\{null}$ \1\&{then}\6
\&{begin} \37$\\{delete\_token\_ref}(\\{split\_first\_mark})$;\5
$\\{split\_first\_mark}\K\\{null}$;\5
$\\{delete\_token\_ref}(\\{split\_bot\_mark})$;\5
$\\{split\_bot\_mark}\K\\{null}$;\6
\&{end};\2\6
\X978:Dispense with trivial cases of void or bad boxes\X;\6
$\|q\K\\{vert\_break}(\\{list\_ptr}(\|v),\39\|h,\39\\{split\_max\_depth})$;\5
\X979:Look at all the marks in nodes before the break, and set the final link
to \\{null} at the break\X;\6
$\|q\K\\{prune\_page\_top}(\|q)$;\5
$\|p\K\\{list\_ptr}(\|v)$;\5
$\\{free\_node}(\|v,\39\\{box\_node\_size})$;\6
\&{if} $\|q=\\{null}$ \1\&{then}\5
$\\{box}(\|n)\K\\{null}$\C{the \\{eq\_level} of the box stays the same}\6
\4\&{else} $\\{box}(\|n)\K\\{vpack}(\|q,\39\\{natural})$;\2\6
$\\{vsplit}\K\\{vpackage}(\|p,\39\|h,\39\\{exactly},\39\\{split\_max\_depth})$;%
\6
\4\\{exit}: \37\&{end};\par
\fi

\M978. \P$\X978:Dispense with trivial cases of void or bad boxes\X\S$\6
\&{if} $\|v=\\{null}$ \1\&{then}\6
\&{begin} \37$\\{vsplit}\K\\{null}$;\5
\&{return};\6
\&{end};\2\6
\&{if} $\\{type}(\|v)\I\\{vlist\_node}$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{""})$;\5
$\\{print\_esc}(\.{"vsplit"})$;\5
$\\{print}(\.{"\ needs\ a\ "})$;\5
$\\{print\_esc}(\.{"vbox"})$;\5
$\\{help2}(\.{"The\ box\ you\ are\ trying\ to\ split\ is\ an\ \\hbox."})$\6
$(\.{"I\ can\'t\ split\ such\ a\ box,\ so\ I\'ll\ leave\ it\ alone."})$;\5
\\{error};\5
$\\{vsplit}\K\\{null}$;\5
\&{return};\6
\&{end}\2\par
\U section~977.\fi

\M979. It's possible that the box begins with a penalty node that is the
``best'' break, so we must be careful to handle this special case correctly.

\Y\P$\4\X979:Look at all the marks in nodes before the break, and set the final
link to \\{null} at the break\X\S$\6
$\|p\K\\{list\_ptr}(\|v)$;\6
\&{if} $\|p=\|q$ \1\&{then}\5
$\\{list\_ptr}(\|v)\K\\{null}$\6
\4\&{else} \~ \1\&{loop}\ \&{begin} \37\&{if} $\\{type}(\|p)=\\{mark\_node}$ \1%
\&{then}\6
\&{if} $\\{split\_first\_mark}=\\{null}$ \1\&{then}\6
\&{begin} \37$\\{split\_first\_mark}\K\\{mark\_ptr}(\|p)$;\5
$\\{split\_bot\_mark}\K\\{split\_first\_mark}$;\5
$\\{token\_ref\_count}(\\{split\_first\_mark})\K\30\\{token\_ref\_count}(%
\\{split\_first\_mark})+2$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{delete\_token\_ref}(\\{split\_bot\_mark})$;\5
$\\{split\_bot\_mark}\K\\{mark\_ptr}(\|p)$;\5
$\\{add\_token\_ref}(\\{split\_bot\_mark})$;\6
\&{end};\2\2\6
\&{if} $\\{link}(\|p)=\|q$ \1\&{then}\6
\&{begin} \37$\\{link}(\|p)\K\\{null}$;\5
\&{goto} \37\\{done};\6
\&{end};\2\6
$\|p\K\\{link}(\|p)$;\6
\&{end};\2\2\6
\4\\{done}: \37\par
\U section~977.\fi

\N980.  \[45] The page builder.
When \TeX\ appends new material to its main vlist in vertical mode, it uses
a method something like \\{vsplit} to decide where a page ends, except that
the calculations are done ``on line'' as new items are placed on the list.
The main complication in this process is that insertions have to be put
into their boxes and removed from the vlist, in a more-or-less optimum manner.

We shall use the term ``current page'' for that part of the main vlist that
is being considered as a candidate for being broken off and sent to the
user's output routine. The current page starts at $\\{link}(\\{page\_head})$,
and
it ends at \\{page\_tail}.  We have $\\{page\_head}=\\{page\_tail}$ if this
list is empty.

Utter chaos would reign if the user kept changing page specifications
while a page is being constructed, so the page builder keeps the pertinent
specifications frozen as soon as the page receives its first box or
insertion.  The global variable \\{page\_contents} is \\{empty} when the
current page contains only mark nodes and content-less whatsit nodes; it
is \\{inserts\_only} if the page contains only insertion nodes in addition to
marks and whatsits.  Glue nodes, kern nodes, and penalty nodes are
discarded until a box or rule node appears, at which time \\{page\_contents}
changes to \\{box\_there}.  As soon as \\{page\_contents} becomes non-%
\\{empty},
the current \\{vsize} and \\{max\_depth} are squirreled away into \\{page%
\_goal}
and \\{page\_max\_depth}; the latter values will be used until the page has
been forwarded to the user's output routine. The \.{\\topskip} adjustment
is made when \\{page\_contents} changes to \\{box\_there}.

Although \\{page\_goal} starts out equal to \\{vsize}, it is decreased by the
scaled natural height-plus-depth of the insertions considered so far, and by
the \.{\\skip} corrections for those insertions. Therefore it represents
the size into which the non-inserted material should fit, assuming that
all insertions in the current page have been made.

The variables \\{best\_page\_break} and \\{least\_page\_cost} correspond
respectively to the variables \\{best\_place} and \\{least\_cost} in the
\\{vert\_break} routine that we have already studied; i.e., they record the
location and value of the best place currently known for breaking the
current page. The value of \\{page\_goal} at the time of the best break is
stored in \\{best\_size}.

\Y\P\D \37$\\{inserts\_only}=1$\C{\\{page\_contents} when an insert node has
been contributed, but no boxes}\par
\P\D \37$\\{box\_there}=2$\C{\\{page\_contents} when a box or rule has been
contributed}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{page\_tail}: \37\\{pointer};\C{the final node on the current page}\6
\4\\{page\_contents}: \37$\\{empty}\to\\{box\_there}$;\C{what is on the current
page so far?}\6
\4\\{page\_max\_depth}: \37\\{scaled};\C{maximum box depth on page being built}%
\6
\4\\{best\_page\_break}: \37\\{pointer};\C{break here to get the best page
known so far}\6
\4\\{least\_page\_cost}: \37\\{integer};\C{the score for this currently best
page}\6
\4\\{best\_size}: \37\\{scaled};\C{its \\{page\_goal}}\par
\fi

\M981. The page builder has another data structure to keep track of insertions.
This is a list of four-word nodes, starting and ending at \\{page\_ins\_head}.
That is, the first element of the list is node $\|r\hbox{$_1$}=\\{link}(\\{page%
\_ins\_head})$;
node $r_j$ is followed by $\|r\hbox{$_{j+1}$}=\\{link}(\|r\hbox{$_j$})$; and if
there are
\|n items we have $\|r\hbox{$_{n+1}$}=\\{page\_ins\_head}$. The \\{subtype}
field of
each node in this list refers to an insertion number; for example, `\.{\\insert
250}' would correspond to a node whose \\{subtype} is $\\{qi}(250)$
(the same as the \\{subtype} field of the relevant \\{ins\_node}). These %
\\{subtype}
fields are in increasing order, and $\\{subtype}(\\{page\_ins\_head})=%
\\{qi}(255)$, so \\{page\_ins\_head} serves as a convenient sentinel
at the end of the list. A record is present for each insertion number that
appears in the current page.

The \\{type} field in these nodes distinguishes two possibilities that
might occur as we look ahead before deciding on the optimum page break.
If $\\{type}(\|r)=\\{inserting}$, then $\\{height}(\|r)$ contains the total of
the
height-plus-depth dimensions of the box and all its inserts seen so far.
If $\\{type}(\|r)=\\{split\_up}$, then no more insertions will be made into
this box,
because at least one previous insertion was too big to fit on the current
page; $\\{broken\_ptr}(\|r)$ points to the node where that insertion will be
split, if \TeX\ decides to split it, $\\{broken\_ins}(\|r)$ points to the
insertion node that was tentatively split, and $\\{height}(\|r)$ includes also
the
natural height plus depth of the part that would be split off.

In both cases, $\\{last\_ins\_ptr}(\|r)$ points to the last \\{ins\_node}
encountered for box $\\{qo}(\\{subtype}(\|r))$ that would be at least partially
inserted on the next page; and $\\{best\_ins\_ptr}(\|r)$ points to the last
such \\{ins\_node} that should actually be inserted, to get the page with
minimum badness among all page breaks considered so far. We have
$\\{best\_ins\_ptr}(\|r)=\\{null}$ if and only if no insertion for this box
should
be made to produce this optimum page.

The data structure definitions here use the fact that the \\{height} field
appears in the fourth word of a box node.

\Y\P\D \37$\\{page\_ins\_node\_size}=4$\C{number of words for a page insertion
node}\par
\P\D \37$\\{inserting}=0$\C{an insertion class that has not yet overflowed}\par
\P\D \37$\\{split\_up}=1$\C{an overflowed insertion class}\par
\P\D \37$\\{broken\_ptr}(\#)\S\\{link}(\#+1)$\C{an insertion for this class
will break here if anywhere}\par
\P\D \37$\\{broken\_ins}(\#)\S\\{info}(\#+1)$\C{this insertion might break at %
\\{broken\_ptr}}\par
\P\D \37$\\{last\_ins\_ptr}(\#)\S\\{link}(\#+2)$\C{the most recent insertion
for this \\{subtype}}\par
\P\D \37$\\{best\_ins\_ptr}(\#)\S\\{info}(\#+2)$\C{the optimum most recent
insertion}\par
\Y\P$\4\X790:Initialize the special list heads and constant nodes\X\mathrel{+}%
\S$\6
$\\{subtype}(\\{page\_ins\_head})\K\\{qi}(255)$;\5
$\\{type}(\\{page\_ins\_head})\K\\{split\_up}$;\5
$\\{link}(\\{page\_ins\_head})\K\\{page\_ins\_head}$;\par
\fi

\M982. An array \\{page\_so\_far} records the heights and depths of everything
on the current page. This array contains six \\{scaled} numbers, like the
similar arrays already considered in \\{line\_break} and \\{vert\_break}; and
it
also contains \\{page\_goal} and \\{page\_depth}, since these values are
all accessible to the user via \\{set\_page\_dimen} commands. The
value of $\\{page\_so\_far}[1]$ is also called \\{page\_total}.  The stretch
and shrink components of the \.{\\skip} corrections for each insertion are
included in \\{page\_so\_far}, but the natural space components of these
corrections are not, since they have been subtracted from \\{page\_goal}.

The variable \\{page\_depth} records the depth of the current page; it has been
adjusted so that it is at most \\{page\_max\_depth}. The variable
\\{last\_glue} points to the glue specification of the most recent node
contributed from the contribution list, if this was a glue node; otherwise
$\\{last\_glue}=\\{max\_halfword}$. (If the contribution list is nonempty,
however, the value of \\{last\_glue} is not necessarily accurate.)
The variables \\{last\_penalty} and \\{last\_kern} are similar.  And
finally, \\{insert\_penalties} holds the sum of the penalties associated with
all split and floating insertions.

\Y\P\D \37$\\{page\_goal}\S\\{page\_so\_far}[0]$\C{desired height of
information on page being built}\par
\P\D \37$\\{page\_total}\S\\{page\_so\_far}[1]$\C{height of the current page}%
\par
\P\D \37$\\{page\_shrink}\S\\{page\_so\_far}[6]$\C{shrinkability of the current
page}\par
\P\D \37$\\{page\_depth}\S\\{page\_so\_far}[7]$\C{depth of the current page}\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{page\_so\_far}: \37\&{array} $[0\to7]$ \1\&{of}\5
\\{scaled};\C{height and glue of the current page}\2\6
\4\\{last\_glue}: \37\\{pointer};\C{used to implement \.{\\lastskip}}\6
\4\\{last\_penalty}: \37\\{integer};\C{used to implement \.{\\lastpenalty}}\6
\4\\{last\_kern}: \37\\{scaled};\C{used to implement \.{\\lastkern}}\6
\4\\{insert\_penalties}: \37\\{integer};\C{sum of the penalties for held-over
insertions}\par
\fi

\M983. \P$\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}%
\S$\6
$\\{primitive}(\.{"pagegoal"},\39\\{set\_page\_dimen},\390)$;\5
$\\{primitive}(\.{"pagetotal"},\39\\{set\_page\_dimen},\391)$;\5
$\\{primitive}(\.{"pagestretch"},\39\\{set\_page\_dimen},\392)$;\5
$\\{primitive}(\.{"pagefilstretch"},\39\\{set\_page\_dimen},\393)$;\5
$\\{primitive}(\.{"pagefillstretch"},\39\\{set\_page\_dimen},\394)$;\5
$\\{primitive}(\.{"pagefilllstretch"},\39\\{set\_page\_dimen},\395)$;\5
$\\{primitive}(\.{"pageshrink"},\39\\{set\_page\_dimen},\396)$;\5
$\\{primitive}(\.{"pagedepth"},\39\\{set\_page\_dimen},\397)$;\par
\fi

\M984. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{set\_page\_dimen}: \37\&{case} $\\{chr\_code}$ \1\&{of}\6
\40: \37$\\{print\_esc}(\.{"pagegoal"})$;\6
\41: \37$\\{print\_esc}(\.{"pagetotal"})$;\6
\42: \37$\\{print\_esc}(\.{"pagestretch"})$;\6
\43: \37$\\{print\_esc}(\.{"pagefilstretch"})$;\6
\44: \37$\\{print\_esc}(\.{"pagefillstretch"})$;\6
\45: \37$\\{print\_esc}(\.{"pagefilllstretch"})$;\6
\46: \37$\\{print\_esc}(\.{"pageshrink"})$;\6
\4\&{othercases} \37$\\{print\_esc}(\.{"pagedepth"})$\2\6
\&{endcases};\par
\fi

\M985. \P\D \37$\\{print\_plus\_end}(\#)\S\\{print}(\#)$;\ \&{end} \par
\P\D $\\{print\_plus}(\#)\S$  \6
\&{if} $\\{page\_so\_far}[\#]\I0$ \1\&{then} \6
\&{begin} \37$\\{print}(\.{"\ plus\ "})$;\5
$\\{print\_scaled}(\\{page\_so\_far}[\#])$;\5
\\{print\_plus\_end}\par
\Y\P\4\&{procedure}\1\  \37\\{print\_totals};\2\6
\&{begin} \37$\\{print\_scaled}(\\{page\_total})$;\5
$\\{print\_plus}(2)(\.{""})$;\5
$\\{print\_plus}(3)(\.{"fil"})$;\5
$\\{print\_plus}(4)(\.{"fill"})$;\5
$\\{print\_plus}(5)(\.{"filll"})$;\6
\&{if} $\\{page\_shrink}\I0$ \1\&{then}\6
\&{begin} \37$\\{print}(\.{"\ minus\ "})$;\5
$\\{print\_scaled}(\\{page\_shrink})$;\6
\&{end};\2\6
\&{end};\par
\fi

\M986. \P$\X986:Show the status of the current page\X\S$\6
\&{if} $\\{page\_head}\I\\{page\_tail}$ \1\&{then}\6
\&{begin} \37$\\{print\_nl}(\.{"\#\#\#\ current\ page:"})$;\6
\&{if} $\\{output\_active}$ \1\&{then}\5
$\\{print}(\.{"\ (held\ over\ for\ next\ output)"})$;\2\6
$\\{show\_box}(\\{link}(\\{page\_head}))$;\6
\&{if} $\\{page\_contents}>\\{empty}$ \1\&{then}\6
\&{begin} \37$\\{print\_nl}(\.{"total\ height\ "})$;\5
\\{print\_totals};\5
$\\{print\_nl}(\.{"\ goal\ height\ "})$;\5
$\\{print\_scaled}(\\{page\_goal})$;\5
$\|r\K\\{link}(\\{page\_ins\_head})$;\6
\&{while} $\|r\I\\{page\_ins\_head}$ \1\&{do}\6
\&{begin} \37\\{print\_ln};\5
$\\{print\_esc}(\.{"insert"})$;\5
$\|t\K\\{qo}(\\{subtype}(\|r))$;\5
$\\{print\_int}(\|t)$;\5
$\\{print}(\.{"\ adds\ "})$;\5
$\|t\K\\{x\_over\_n}(\\{height}(\|r),\391000)\ast\\{count}(\|t)$;\5
$\\{print\_scaled}(\|t)$;\6
\&{if} $\\{type}(\|r)=\\{split\_up}$ \1\&{then}\6
\&{begin} \37$\|q\K\\{page\_head}$;\5
$\|t\K0$;\6
\1\&{repeat} \37$\|q\K\\{link}(\|q)$;\6
\&{if} $(\\{type}(\|q)=\\{ins\_node})\W(\\{subtype}(\|q)=\\{subtype}(\|r))$ \1%
\&{then}\5
$\\{incr}(\|t)$;\2\6
\4\&{until}\5
$\|q=\\{broken\_ins}(\|r)$;\2\6
$\\{print}(\.{",\ \#"})$;\5
$\\{print\_int}(\|t)$;\5
$\\{print}(\.{"\ might\ split"})$;\6
\&{end};\2\6
$\|r\K\\{link}(\|r)$;\6
\&{end};\2\6
\&{end};\2\6
\&{end}\2\par
\U section~218.\fi

\M987. Here is a procedure that is called when the \\{page\_contents} is
changing
from \\{empty} to \\{inserts\_only} or \\{box\_there}.

\Y\P\D \37$\\{set\_page\_so\_far\_zero}(\#)\S\\{page\_so\_far}[\#]\K0$\par
\Y\P\4\&{procedure}\1\  \37$\\{freeze\_page\_specs}(\|s:\\{small\_number})$;\2\6
\&{begin} \37$\\{page\_contents}\K\|s$;\5
$\\{page\_goal}\K\\{vsize}$;\5
$\\{page\_max\_depth}\K\\{max\_depth}$;\5
$\\{page\_depth}\K0$;\5
$\\{do\_all\_six}(\\{set\_page\_so\_far\_zero})$;\5
$\\{least\_page\_cost}\K\\{awful\_bad}$;\6
\&{stat} \37\&{if} $\\{tracing\_pages}>0$ \1\&{then}\6
\&{begin} \37\\{begin\_diagnostic};\5
$\\{print\_nl}(\.{"\%\%\ goal\ height="})$;\5
$\\{print\_scaled}(\\{page\_goal})$;\5
$\\{print}(\.{",\ max\ depth="})$;\5
$\\{print\_scaled}(\\{page\_max\_depth})$;\5
$\\{end\_diagnostic}(\\{false})$;\6
\&{end};\2\ \&{tats}\6
\&{end};\par
\fi

\M988. Pages are built by appending nodes to the current list in \TeX's
vertical mode, which is at the outermost level of the semantic nest. This
vlist is split into two parts; the ``current page'' that we have been
talking so much about already, and the ``contribution list'' that receives
new nodes as they are created.  The current page contains everything that
the page builder has accounted for in its data structures, as described
above, while the contribution list contains other things that have been
generated by other parts of \TeX\ but not yet seen by the page builder.
The contribution list starts at $\\{link}(\\{contrib\_head})$, and it ends at
the
current node in \TeX's vertical mode.

When \TeX\ has appended new material in vertical mode, it calls the procedure
\\{build\_page}, which tries to catch up by moving nodes from the contribution
list to the current page. This procedure will succeed in its goal of
emptying the contribution list, unless a page break is discovered, i.e.,
unless the current page has grown to the point where the optimum next
page break has been determined. In the latter case, the nodes after the
optimum break will go back onto the contribution list, and control will
effectively pass to the user's output routine.

We make $\\{type}(\\{page\_head})=\\{glue\_node}$, so that an initial glue node
on
the current page will not be considered a valid breakpoint.

\Y\P$\4\X790:Initialize the special list heads and constant nodes\X\mathrel{+}%
\S$\6
$\\{type}(\\{page\_head})\K\\{glue\_node}$;\5
$\\{subtype}(\\{page\_head})\K\\{normal}$;\par
\fi

\M989. The global variable \\{output\_active} is true during the time the
user's output routine is driving \TeX.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{output\_active}: \37\\{boolean};\C{are we in the midst of an output
routine?}\par
\fi

\M990. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{output\_active}\K\\{false}$;\5
$\\{insert\_penalties}\K0$;\par
\fi

\M991. The page builder is ready to start a fresh page if we initialize
the following state variables. (However, the page insertion list is initialized
elsewhere.)

\Y\P$\4\X991:Start a new current page\X\S$\6
$\\{page\_contents}\K\\{empty}$;\5
$\\{page\_tail}\K\\{page\_head}$;\5
$\\{link}(\\{page\_head})\K\\{null}$;\6
$\\{last\_glue}\K\\{max\_halfword}$;\5
$\\{last\_penalty}\K0$;\5
$\\{last\_kern}\K0$;\5
$\\{page\_depth}\K0$;\5
$\\{page\_max\_depth}\K0$\par
\U sections~215 and~1017.\fi

\M992. At certain times box 255 is supposed to be void (i.e., \\{null}),
or an insertion box is supposed to be ready to accept a vertical list.
If not, an error message is printed, and the following subroutine
flushes the unwanted contents, reporting them to the user.

\Y\P\4\&{procedure}\1\  \37$\\{box\_error}(\|n:\\{eight\_bits})$;\2\6
\&{begin} \37\\{error};\5
\\{begin\_diagnostic};\5
$\\{print\_nl}(\.{"The\ following\ box\ has\ been\ deleted:"})$;\5
$\\{show\_box}(\\{box}(\|n))$;\5
$\\{end\_diagnostic}(\\{true})$;\5
$\\{flush\_node\_list}(\\{box}(\|n))$;\5
$\\{box}(\|n)\K\\{null}$;\6
\&{end};\par
\fi

\M993. The following procedure guarantees that a given box register
does not contain an \.{\\hbox}.

\Y\P\4\&{procedure}\1\  \37$\\{ensure\_vbox}(\|n:\\{eight\_bits})$;\6
\4\&{var} \37\|p: \37\\{pointer};\C{the box register contents}\2\6
\&{begin} \37$\|p\K\\{box}(\|n)$;\6
\&{if} $\|p\I\\{null}$ \1\&{then}\6
\&{if} $\\{type}(\|p)=\\{hlist\_node}$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Insertions\ can\ only\ be\ added\ to\ a\
vbox"})$;\5
$\\{help3}(\.{"Tut\ tut:\ You\'re\ trying\ to\ \\insert\ into\ a"})$\6
$(\.{"\\box\ register\ that\ now\ contains\ an\ \\hbox."})$\6
$(\.{"Proceed,\ and\ I\'ll\ discard\ its\ present\ contents."})$;\5
$\\{box\_error}(\|n)$;\6
\&{end};\2\2\6
\&{end};\par
\fi

\M994. \TeX\ is not always in vertical mode at the time \\{build\_page}
is called; the current mode reflects what \TeX\ should return to, after
the contribution list has been emptied. A call on \\{build\_page} should
be immediately followed by `\&{goto} \\{big\_switch}', which is \TeX's central
control point.

\Y\P\D \37$\\{contribute}=80$\C{go here to link a node into the current page}%
\par
\Y\P\hbox{\4}\X1012:Declare the procedure called \\{fire\_up}\X\6
\4\&{procedure}\1\  \37\\{build\_page};\C{append contributions to the current
page}\6
\4\&{label} \37$\\{exit},\39\\{done},\39\\{done1},\39\\{continue},\39%
\\{contribute},\39\\{update\_heights}$;\6
\4\&{var} \37\|p: \37\\{pointer};\C{the node being appended}\6
$\|q,\39\|r$: \37\\{pointer};\C{nodes being examined}\6
$\|b,\39\|c$: \37\\{integer};\C{badness and cost of current page}\6
\\{pi}: \37\\{integer};\C{penalty to be added to the badness}\6
\|n: \37$\\{min\_quarterword}\to255$;\C{insertion box number}\6
$\\{delta},\39\|h,\39\|w$: \37\\{scaled};\C{sizes used for insertion
calculations}\2\6
\&{begin} \37\&{if} $(\\{link}(\\{contrib\_head})=\\{null})\V\\{output%
\_active}$ \1\&{then}\5
\&{return};\2\6
\1\&{repeat} \37\\{continue}: \37$\|p\K\\{link}(\\{contrib\_head})$;\6
\X996:Update the values of \\{last\_glue}, \\{last\_penalty}, and \\{last%
\_kern}\X;\6
\X997:Move node \|p to the current page; if it is time for a page break, put
the nodes following the break back onto the contribution list, and \&{return}
to the user's output routine if there is one\X;\6
\4\&{until}\5
$\\{link}(\\{contrib\_head})=\\{null}$;\2\6
\X995:Make the contribution list empty by setting its tail to \\{contrib\_head}%
\X;\6
\4\\{exit}: \37\&{end};\par
\fi

\M995. \P\D \37$\\{contrib\_tail}\S\\{nest}[0].\\{tail\_field}$\C{tail of the
contribution list}\par
\Y\P$\4\X995:Make the contribution list empty by setting its tail to \\{contrib%
\_head}\X\S$\6
\&{if} $\\{nest\_ptr}=0$ \1\&{then}\5
$\\{tail}\K\\{contrib\_head}$\C{vertical mode}\6
\4\&{else} $\\{contrib\_tail}\K\\{contrib\_head}$\C{other modes}\2\par
\U section~994.\fi

\M996. \P$\X996:Update the values of \\{last\_glue}, \\{last\_penalty}, and %
\\{last\_kern}\X\S$\6
\&{if} $\\{last\_glue}\I\\{max\_halfword}$ \1\&{then}\5
$\\{delete\_glue\_ref}(\\{last\_glue})$;\2\6
$\\{last\_penalty}\K0$;\5
$\\{last\_kern}\K0$;\6
\&{if} $\\{type}(\|p)=\\{glue\_node}$ \1\&{then}\6
\&{begin} \37$\\{last\_glue}\K\\{glue\_ptr}(\|p)$;\5
$\\{add\_glue\_ref}(\\{last\_glue})$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{last\_glue}\K\\{max\_halfword}$;\6
\&{if} $\\{type}(\|p)=\\{penalty\_node}$ \1\&{then}\5
$\\{last\_penalty}\K\\{penalty}(\|p)$\6
\4\&{else} \&{if} $\\{type}(\|p)=\\{kern\_node}$ \1\&{then}\5
$\\{last\_kern}\K\\{width}(\|p)$;\2\2\6
\&{end}\2\par
\U section~994.\fi

\M997. The code here is an example of a many-way switch into routines that
merge together in different places. Some people call this unstructured
programming, but the author doesn't see much wrong with it, as long as
the various labels have a well-understood meaning.

\Y\P$\4\X997:Move node \|p to the current page; if it is time for a page break,
put the nodes following the break back onto the contribution list, and %
\&{return} to the user's output routine if there is one\X\S$\6
\X1000:If the current page is empty and node \|p is to be deleted, \&{goto} %
\\{done1}; otherwise use node \|p to update the state of the current page; if
this node is an insertion, \&{goto} \\{contribute}; otherwise if this node is
not a legal breakpoint, \&{goto} \\{contribute} or \\{update\_heights};
otherwise set \\{pi} to the penalty associated with this breakpoint\X;\6
\X1005:Check if node \|p is a new champion breakpoint; then \(if)if it is time
for a page break, prepare for output, and either fire up the user's output
routine and \&{return} or ship out the page and \&{goto} \\{done}\X;\6
\&{if} $(\\{type}(\|p)<\\{glue\_node})\V(\\{type}(\|p)>\\{kern\_node})$ \1%
\&{then}\5
\&{goto} \37\\{contribute};\2\6
\4\\{update\_heights}: \37\X1004:Update the current page measurements with
respect to the glue or kern specified by node~\|p\X;\6
\4\\{contribute}: \37\X1003:Make sure that \\{page\_max\_depth} is not exceeded%
\X;\6
\X998:Link node \|p into the current page and \&{goto} \\{done}\X;\6
\4\\{done1}: \37\X999:Recycle node \|p\X;\6
\4\\{done}: \37\par
\U section~994.\fi

\M998. \P$\X998:Link node \|p into the current page and \&{goto} \\{done}\X\S$\6
$\\{link}(\\{page\_tail})\K\|p$;\5
$\\{page\_tail}\K\|p$;\5
$\\{link}(\\{contrib\_head})\K\\{link}(\|p)$;\5
$\\{link}(\|p)\K\\{null}$;\5
\&{goto} \37\\{done}\par
\U section~997.\fi

\M999. \P$\X999:Recycle node \|p\X\S$\6
$\\{link}(\\{contrib\_head})\K\\{link}(\|p)$;\5
$\\{link}(\|p)\K\\{null}$;\5
$\\{flush\_node\_list}(\|p)$\par
\U section~997.\fi

\M1000. The title of this section is already so long, it seems best to avoid
making it more accurate but still longer, by mentioning the fact that a
kern node at the end of the contribution list will not be contributed until
we know its successor.

\Y\P$\4\X1000:If the current page is empty and node \|p is to be deleted, %
\&{goto} \\{done1}; otherwise use node \|p to update the state of the current
page; if this node is an insertion, \&{goto} \\{contribute}; otherwise if this
node is not a legal breakpoint, \&{goto} \\{contribute} or \\{update\_heights};
otherwise set \\{pi} to the penalty associated with this breakpoint\X\S$\6
\&{case} $\\{type}(\|p)$ \1\&{of}\6
\4$\\{hlist\_node},\39\\{vlist\_node},\39\\{rule\_node}$: \37\&{if} $\\{page%
\_contents}<\\{box\_there}$ \1\&{then}\5
\X1001:Initialize the current page, insert the \.{\\topskip} glue ahead of \|p,
and \&{goto} \\{continue}\X\6
\4\&{else} \X1002:Prepare to move a box or rule node to the current page, then %
\&{goto} \\{contribute}\X;\2\6
\4\\{whatsit\_node}: \37\X1363:Prepare to move whatsit \|p to the current page,
then \&{goto} \\{contribute}\X;\6
\4\\{glue\_node}: \37\&{if} $\\{page\_contents}<\\{box\_there}$ \1\&{then}\5
\&{goto} \37\\{done1}\6
\4\&{else} \&{if} $\\{precedes\_break}(\\{page\_tail})$ \1\&{then}\5
$\\{pi}\K0$\6
\4\&{else} \&{goto} \37\\{update\_heights};\2\2\6
\4\\{kern\_node}: \37\&{if} $\\{page\_contents}<\\{box\_there}$ \1\&{then}\5
\&{goto} \37\\{done1}\6
\4\&{else} \&{if} $\\{link}(\|p)=\\{null}$ \1\&{then}\5
\&{return}\6
\4\&{else} \&{if} $\\{type}(\\{link}(\|p))=\\{glue\_node}$ \1\&{then}\5
$\\{pi}\K0$\6
\4\&{else} \&{goto} \37\\{update\_heights};\2\2\2\6
\4\\{penalty\_node}: \37\&{if} $\\{page\_contents}<\\{box\_there}$ \1\&{then}\5
\&{goto} \37\\{done1}\ \&{else} $\\{pi}\K\\{penalty}(\|p)$;\2\6
\4\\{mark\_node}: \37\&{goto} \37\\{contribute};\6
\4\\{ins\_node}: \37\X1008:Append an insertion to the current page and \&{goto}
\\{contribute}\X;\6
\4\&{othercases} \37$\\{confusion}(\.{"page"})$\2\6
\&{endcases}\par
\U section~997.\fi

\M1001. \P$\X1001:Initialize the current page, insert the \.{\\topskip} glue
ahead of \|p, and \&{goto} \\{continue}\X\S$\6
\&{begin} \37\&{if} $\\{page\_contents}=\\{empty}$ \1\&{then}\5
$\\{freeze\_page\_specs}(\\{box\_there})$\6
\4\&{else} $\\{page\_contents}\K\\{box\_there}$;\2\6
$\|q\K\\{new\_skip\_param}(\\{top\_skip\_code})$;\5
$\\{link}(\|q)\K\|p$;\C{now $\\{temp\_ptr}=\\{glue\_ptr}(\|q)$}\6
\&{if} $\\{width}(\\{temp\_ptr})>\\{height}(\|p)$ \1\&{then}\5
$\\{width}(\\{temp\_ptr})\K\\{width}(\\{temp\_ptr})-\\{height}(\|p)$\6
\4\&{else} $\\{width}(\\{temp\_ptr})\K0$;\2\6
$\\{link}(\|q)\K\|p$;\5
$\\{link}(\\{contrib\_head})\K\|q$;\5
\&{goto} \37\\{continue};\6
\&{end}\par
\U section~1000.\fi

\M1002. \P$\X1002:Prepare to move a box or rule node to the current page, then %
\&{goto} \\{contribute}\X\S$\6
\&{begin} \37$\\{page\_total}\K\\{page\_total}+\\{page\_depth}+\\{height}(%
\|p)$;\5
$\\{page\_depth}\K\\{depth}(\|p)$;\5
\&{goto} \37\\{contribute};\6
\&{end}\par
\U section~1000.\fi

\M1003. \P$\X1003:Make sure that \\{page\_max\_depth} is not exceeded\X\S$\6
\&{if} $\\{page\_depth}>\\{page\_max\_depth}$ \1\&{then}\6
\&{begin} \37$\\{page\_total}\K\30\\{page\_total}+\\{page\_depth}-\\{page\_max%
\_depth}$;\6
$\\{page\_depth}\K\\{page\_max\_depth}$;\6
\&{end};\2\par
\U section~997.\fi

\M1004. \P$\X1004:Update the current page measurements with respect to the glue
or kern specified by node~\|p\X\S$\6
\&{if} $\\{type}(\|p)=\\{kern\_node}$ \1\&{then}\5
$\|q\K\|p$\6
\4\&{else} \&{begin} \37$\|q\K\\{glue\_ptr}(\|p)$;\5
$\\{page\_so\_far}[2+\\{stretch\_order}(\|q)]\K\30\\{page\_so\_far}[2+%
\\{stretch\_order}(\|q)]+\\{stretch}(\|q)$;\6
$\\{page\_shrink}\K\\{page\_shrink}+\\{shrink}(\|q)$;\6
\&{if} $(\\{shrink\_order}(\|q)\I\\{normal})\W(\\{shrink}(\|q)\I0)$ \1\&{then}\6
\&{begin} \37\hbox{}\6
$\\{print\_err}(\.{"Infinite\ glue\ shrinkage\ found\ on\ current\ page"})$;\6
$\\{help4}(\.{"The\ page\ about\ to\ be\ output\ contains\ some\ infinitely"})$%
\6
$(\.{"shrinkable\ glue,\ e.g.,\ \`\\vss\'\ or\ \`\\vskip\ 0pt\ minus\ 1fil%
\'."})$\6
$(\.{"Such\ glue\ doesn\'t\ belong\ there;\ but\ you\ can\ safely\ proceed,"})$%
\6
$(\.{"since\ the\ offensive\ shrinkability\ has\ been\ made\ finite."})$;\5
\\{error};\5
$\|r\K\\{new\_spec}(\|q)$;\5
$\\{shrink\_order}(\|r)\K\\{normal}$;\5
$\\{delete\_glue\_ref}(\|q)$;\5
$\\{glue\_ptr}(\|p)\K\|r$;\6
\&{end};\2\6
\&{end};\2\6
$\\{page\_total}\K\\{page\_total}+\\{page\_depth}+\\{width}(\|q)$;\5
$\\{page\_depth}\K0$\par
\U section~997.\fi

\M1005. \P$\X1005:Check if node \|p is a new champion breakpoint; then \(if)if
it is time for a page break, prepare for output, and either fire up the user's
output routine and \&{return} or ship out the page and \&{goto} \\{done}\X\S$\6
\&{if} $\\{pi}<\\{inf\_penalty}$ \1\&{then}\6
\&{begin} \37\X1007:Compute the badness, \|b, of the current page, using %
\\{awful\_bad} if the box is too full\X;\6
\&{if} $\|b<\\{awful\_bad}$ \1\&{then}\6
\&{if} $\\{pi}\L\\{eject\_penalty}$ \1\&{then}\5
$\|c\K\\{pi}$\6
\4\&{else} \&{if} $\|b<\\{inf\_bad}$ \1\&{then}\5
$\|c\K\|b+\\{pi}+\\{insert\_penalties}$\6
\4\&{else} $\|c\K\\{deplorable}$\2\2\6
\4\&{else} $\|c\K\|b$;\2\6
\&{if} $\\{insert\_penalties}\G10000$ \1\&{then}\5
$\|c\K\\{awful\_bad}$;\2\6
\&{stat} \37\&{if} $\\{tracing\_pages}>0$ \1\&{then}\5
\X1006:Display page break cost\X;\ \2\6
\&{tats}\6
\&{if} $\|c\L\\{least\_page\_cost}$ \1\&{then}\6
\&{begin} \37$\\{best\_page\_break}\K\|p$;\5
$\\{best\_size}\K\\{page\_goal}$;\5
$\\{least\_page\_cost}\K\|c$;\5
$\|r\K\\{link}(\\{page\_ins\_head})$;\6
\&{while} $\|r\I\\{page\_ins\_head}$ \1\&{do}\6
\&{begin} \37$\\{best\_ins\_ptr}(\|r)\K\\{last\_ins\_ptr}(\|r)$;\5
$\|r\K\\{link}(\|r)$;\6
\&{end};\2\6
\&{end};\2\6
\&{if} $(\|c=\\{awful\_bad})\V(\\{pi}\L\\{eject\_penalty})$ \1\&{then}\6
\&{begin} \37$\\{fire\_up}(\|p)$;\C{output the current page at the best place}\6
\&{if} $\\{output\_active}$ \1\&{then}\5
\&{return};\C{user's output routine will act}\2\6
\&{goto} \37\\{done};\C{the page has been shipped out by default output
routine}\6
\&{end};\2\6
\&{end}\2\par
\U section~997.\fi

\M1006. \P$\X1006:Display page break cost\X\S$\6
\&{begin} \37\\{begin\_diagnostic};\5
$\\{print\_nl}(\.{"\%"})$;\5
$\\{print}(\.{"\ t="})$;\5
\\{print\_totals};\6
$\\{print}(\.{"\ g="})$;\5
$\\{print\_scaled}(\\{page\_goal})$;\6
$\\{print}(\.{"\ b="})$;\6
\&{if} $\|b=\\{awful\_bad}$ \1\&{then}\5
$\\{print\_char}(\.{"*"})$\ \&{else} $\\{print\_int}(\|b)$;\2\6
$\\{print}(\.{"\ p="})$;\5
$\\{print\_int}(\\{pi})$;\5
$\\{print}(\.{"\ c="})$;\6
\&{if} $\|c=\\{awful\_bad}$ \1\&{then}\5
$\\{print\_char}(\.{"*"})$\ \&{else} $\\{print\_int}(\|c)$;\2\6
\&{if} $\|c\L\\{least\_page\_cost}$ \1\&{then}\5
$\\{print\_char}(\.{"\#"})$;\2\6
$\\{end\_diagnostic}(\\{false})$;\6
\&{end}\par
\U section~1005.\fi

\M1007. \P$\X1007:Compute the badness, \|b, of the current page, using \\{awful%
\_bad} if the box is too full\X\S$\6
\&{if} $\\{page\_total}<\\{page\_goal}$ \1\&{then}\6
\&{if} $(\\{page\_so\_far}[3]\I0)\V(\\{page\_so\_far}[4]\I0)\V\30(\\{page\_so%
\_far}[5]\I0)$ \1\&{then}\5
$\|b\K0$\6
\4\&{else} $\|b\K\\{badness}(\\{page\_goal}-\\{page\_total},\39\\{page\_so%
\_far}[2])$\2\6
\4\&{else} \&{if} $\\{page\_total}-\\{page\_goal}>\\{page\_shrink}$ \1\&{then}\5
$\|b\K\\{awful\_bad}$\6
\4\&{else} $\|b\K\\{badness}(\\{page\_total}-\\{page\_goal},\39\\{page%
\_shrink})$\2\2\par
\U section~1005.\fi

\M1008. \P$\X1008:Append an insertion to the current page and \&{goto} %
\\{contribute}\X\S$\6
\&{begin} \37\&{if} $\\{page\_contents}=\\{empty}$ \1\&{then}\5
$\\{freeze\_page\_specs}(\\{inserts\_only})$;\2\6
$\|n\K\\{subtype}(\|p)$;\5
$\|r\K\\{page\_ins\_head}$;\6
\&{while} $\|n\G\\{subtype}(\\{link}(\|r))$ \1\&{do}\5
$\|r\K\\{link}(\|r)$;\2\6
$\|n\K\\{qo}(\|n)$;\6
\&{if} $\\{subtype}(\|r)\I\\{qi}(\|n)$ \1\&{then}\5
\X1009:Create a page insertion node with $\\{subtype}(\|r)=\\{qi}(\|n)$, and
include the glue correction for box \|n in the current page state\X;\2\6
\&{if} $\\{type}(\|r)=\\{split\_up}$ \1\&{then}\5
$\\{insert\_penalties}\K\\{insert\_penalties}+\\{float\_cost}(\|p)$\6
\4\&{else} \&{begin} \37$\\{last\_ins\_ptr}(\|r)\K\|p$;\5
$\\{delta}\K\\{page\_goal}-\\{page\_total}-\\{page\_depth}+\\{page\_shrink}$;%
\C{this much room is left if we shrink the maximum}\6
\&{if} $\\{count}(\|n)=1000$ \1\&{then}\5
$\|h\K\\{height}(\|p)$\6
\4\&{else} $\|h\K\\{x\_over\_n}(\\{height}(\|p),\391000)\ast\\{count}(\|n)$;%
\C{this much room is needed}\2\6
\&{if} $((\|h\L0)\V(\|h\L\\{delta}))\W(\\{height}(\|p)+\\{height}(\|r)\L%
\\{dimen}(\|n))$ \1\&{then}\6
\&{begin} \37$\\{page\_goal}\K\\{page\_goal}-\|h$;\5
$\\{height}(\|r)\K\\{height}(\|r)+\\{height}(\|p)$;\6
\&{end}\6
\4\&{else} \X1010:Find the best way to split the insertion, and change $%
\\{type}(\|r)$ to \\{split\_up}\X;\2\6
\&{end};\2\6
\&{goto} \37\\{contribute};\6
\&{end}\par
\U section~1000.\fi

\M1009. We take note of the value of \.{\\skip} \|n and the height plus depth
of \.{\\box}~\|n only when the first \.{\\insert}~\|n node is
encountered for a new page. A user who changes the contents of \.{\\box}~\|n
after that first \.{\\insert}~\|n had better be either extremely careful
or extremely lucky, or both.

\Y\P$\4\X1009:Create a page insertion node with $\\{subtype}(\|r)=\\{qi}(\|n)$,
and include the glue correction for box \|n in the current page state\X\S$\6
\&{begin} \37$\|q\K\\{get\_node}(\\{page\_ins\_node\_size})$;\5
$\\{link}(\|q)\K\\{link}(\|r)$;\5
$\\{link}(\|r)\K\|q$;\5
$\|r\K\|q$;\5
$\\{subtype}(\|r)\K\\{qi}(\|n)$;\5
$\\{type}(\|r)\K\\{inserting}$;\5
$\\{ensure\_vbox}(\|n)$;\6
\&{if} $\\{box}(\|n)=\\{null}$ \1\&{then}\5
$\\{height}(\|r)\K0$\6
\4\&{else} $\\{height}(\|r)\K\\{height}(\\{box}(\|n))+\\{depth}(\\{box}(\|n))$;%
\2\6
$\\{best\_ins\_ptr}(\|r)\K\\{null}$;\6
$\|q\K\\{skip}(\|n)$;\6
\&{if} $\\{count}(\|n)=1000$ \1\&{then}\5
$\|h\K\\{height}(\|r)$\6
\4\&{else} $\|h\K\\{x\_over\_n}(\\{height}(\|r),\391000)\ast\\{count}(\|n)$;\2\6
$\\{page\_goal}\K\\{page\_goal}-\|h-\\{width}(\|q)$;\6
$\\{page\_so\_far}[2+\\{stretch\_order}(\|q)]\K\30\\{page\_so\_far}[2+%
\\{stretch\_order}(\|q)]+\\{stretch}(\|q)$;\6
$\\{page\_shrink}\K\\{page\_shrink}+\\{shrink}(\|q)$;\6
\&{if} $(\\{shrink\_order}(\|q)\I\\{normal})\W(\\{shrink}(\|q)\I0)$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Infinite\ glue\ shrinkage\ inserted\ from\
"})$;\5
$\\{print\_esc}(\.{"skip"})$;\5
$\\{print\_int}(\|n)$;\5
$\\{help3}(\.{"The\ correction\ glue\ for\ page\ breaking\ with\ insertions"})$%
\6
$(\.{"must\ have\ finite\ shrinkability.\ But\ you\ may\ proceed,"})$\6
$(\.{"since\ the\ offensive\ shrinkability\ has\ been\ made\ finite."})$;\5
\\{error};\6
\&{end};\2\6
\&{end}\par
\U section~1008.\fi

\M1010. Here is the code that will split a long footnote between pages, in an
emergency. The current situation deserves to be recapitulated: Node \|p
is an insertion into box \|n; the insertion will not fit, in its entirety,
either because it would make the total contents of box \|n greater than
\.{\\dimen} \|n, or because it would make the incremental amount of growth
\|h greater than the available space \\{delta}, or both. (This amount \|h has
been weighted by the insertion scaling factor, i.e., by \.{\\count} \|n
over 1000.) Now we will choose the best way to break the vlist of the
insertion, using the same criteria as in the \.{\\vsplit} operation.

\Y\P$\4\X1010:Find the best way to split the insertion, and change $\\{type}(%
\|r)$ to \\{split\_up}\X\S$\6
\&{begin} \37\&{if} $\\{count}(\|n)\L0$ \1\&{then}\5
$\|w\K\\{max\_dimen}$\6
\4\&{else} \&{begin} \37$\|w\K\\{page\_goal}-\\{page\_total}-\\{page\_depth}$;\6
\&{if} $\\{count}(\|n)\I1000$ \1\&{then}\5
$\|w\K\\{x\_over\_n}(\|w,\39\\{count}(\|n))\ast1000$;\2\6
\&{end};\2\6
\&{if} $\|w>\\{dimen}(\|n)-\\{height}(\|r)$ \1\&{then}\5
$\|w\K\\{dimen}(\|n)-\\{height}(\|r)$;\2\6
$\|q\K\\{vert\_break}(\\{ins\_ptr}(\|p),\39\|w,\39\\{depth}(\|p))$;\5
$\\{height}(\|r)\K\\{height}(\|r)+\\{best\_height\_plus\_depth}$;\6
\&{stat} \37\&{if} $\\{tracing\_pages}>0$ \1\&{then}\5
\X1011:Display insertion split cost\X;\ \2\6
\&{tats}\6
\&{if} $\\{count}(\|n)\I1000$ \1\&{then}\5
$\\{best\_height\_plus\_depth}\K\\{x\_over\_n}(\\{best\_height\_plus\_depth},%
\391000)\ast\\{count}(\|n)$;\2\6
$\\{page\_goal}\K\\{page\_goal}-\\{best\_height\_plus\_depth}$;\5
$\\{type}(\|r)\K\\{split\_up}$;\5
$\\{broken\_ptr}(\|r)\K\|q$;\5
$\\{broken\_ins}(\|r)\K\|p$;\6
\&{if} $\|q=\\{null}$ \1\&{then}\5
$\\{insert\_penalties}\K\\{insert\_penalties}+\\{eject\_penalty}$\6
\4\&{else} \&{if} $\\{type}(\|q)=\\{penalty\_node}$ \1\&{then}\5
$\\{insert\_penalties}\K\\{insert\_penalties}+\\{penalty}(\|q)$;\2\2\6
\&{end}\par
\U section~1008.\fi

\M1011. \P$\X1011:Display insertion split cost\X\S$\6
\&{begin} \37\\{begin\_diagnostic};\5
$\\{print\_nl}(\.{"\%\ split"})$;\5
$\\{print\_int}(\|n)$;\5
$\\{print}(\.{"\ to\ "})$;\5
$\\{print\_scaled}(\|w)$;\5
$\\{print\_char}(\.{","})$;\5
$\\{print\_scaled}(\\{best\_height\_plus\_depth})$;\6
$\\{print}(\.{"\ p="})$;\6
\&{if} $\|q=\\{null}$ \1\&{then}\5
$\\{print\_int}(\\{eject\_penalty})$\6
\4\&{else} \&{if} $\\{type}(\|q)=\\{penalty\_node}$ \1\&{then}\5
$\\{print\_int}(\\{penalty}(\|q))$\6
\4\&{else} $\\{print\_char}(\.{"0"})$;\2\2\6
$\\{end\_diagnostic}(\\{false})$;\6
\&{end}\par
\U section~1010.\fi

\M1012. When the page builder has looked at as much material as could appear
before
the next page break, it makes its decision. The break that gave minimum
badness will be used to put a completed ``page'' into box 255, with insertions
appended to their other boxes.

We also set the values of \\{top\_mark}, \\{first\_mark}, and \\{bot\_mark}.
The
program uses the fact that $\\{bot\_mark}\I\\{null}$ implies $\\{first\_mark}\I%
\\{null}$;
$\\{bot\_mark}=\\{null}$ implies $\\{top\_mark}=\\{first\_mark}=\\{null}$.

The \\{fire\_up} subroutine prepares to output the current page at the best
place; then it fires up the user's output routine, if there is one,
or it simply ships out the page. There is one parameter, \|c, which represents
the node that was being contributed to the page when the decision to
force an output was made.

\Y\P$\4\X1012:Declare the procedure called \\{fire\_up}\X\S$\6
\4\&{procedure}\1\  \37$\\{fire\_up}(\|c:\\{pointer})$;\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37$\|p,\39\|q,\39\|r,\39\|s$: \37\\{pointer};\C{nodes being examined
and/or changed}\6
\\{prev\_p}: \37\\{pointer};\C{predecessor of \|p}\6
\|n: \37$\\{min\_quarterword}\to255$;\C{insertion box number}\6
\\{wait}: \37\\{boolean};\C{should the present insertion be held over?}\6
\\{save\_vbadness}: \37\\{integer};\C{saved value of \\{vbadness}}\6
\\{save\_vfuzz}: \37\\{scaled};\C{saved value of \\{vfuzz}}\6
\\{save\_split\_top\_skip}: \37\\{pointer};\C{saved value of \\{split\_top%
\_skip}}\2\6
\&{begin} \37\X1013:Set the value of \\{output\_penalty}\X;\6
\&{if} $\\{bot\_mark}\I\\{null}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{top\_mark}\I\\{null}$ \1\&{then}\5
$\\{delete\_token\_ref}(\\{top\_mark})$;\2\6
$\\{top\_mark}\K\\{bot\_mark}$;\5
$\\{add\_token\_ref}(\\{top\_mark})$;\5
$\\{delete\_token\_ref}(\\{first\_mark})$;\5
$\\{first\_mark}\K\\{null}$;\6
\&{end};\2\6
\X1014:Put the \(o)optimal current page into box 255, update \\{first\_mark}
and \\{bot\_mark}, append insertions to their boxes, and put the remaining
nodes back on the contribution list\X;\6
\&{if} $(\\{top\_mark}\I\\{null})\W(\\{first\_mark}=\\{null})$ \1\&{then}\6
\&{begin} \37$\\{first\_mark}\K\\{top\_mark}$;\5
$\\{add\_token\_ref}(\\{top\_mark})$;\6
\&{end};\2\6
\&{if} $\\{output\_routine}\I\\{null}$ \1\&{then}\6
\&{if} $\\{dead\_cycles}\G\\{max\_dead\_cycles}$ \1\&{then}\5
\X1024:Explain that too many dead cycles have occurred in a row\X\6
\4\&{else} \X1025:Fire up the user's output routine and \&{return}\X;\2\2\6
\X1023:Perform the default output routine\X;\6
\4\\{exit}: \37\&{end};\par
\U section~994.\fi

\M1013. \P$\X1013:Set the value of \\{output\_penalty}\X\S$\6
\&{if} $\\{type}(\\{best\_page\_break})=\\{penalty\_node}$ \1\&{then}\6
\&{begin} \37$\\{geq\_word\_define}(\\{int\_base}+\\{output\_penalty\_code},\39%
\\{penalty}(\\{best\_page\_break}))$;\5
$\\{penalty}(\\{best\_page\_break})\K\\{inf\_penalty}$;\6
\&{end}\6
\4\&{else} $\\{geq\_word\_define}(\\{int\_base}+\\{output\_penalty\_code},\39%
\\{inf\_penalty})$\2\par
\U section~1012.\fi

\M1014. As the page is finally being prepared for output, \|p runs through the
vlist,
with \\{prev\_p} trailing behind, and \|q is the tail of a list of insertions
that
are being held over for a subsequent page.

\Y\P$\4\X1014:Put the \(o)optimal current page into box 255, update \\{first%
\_mark} and \\{bot\_mark}, append insertions to their boxes, and put the
remaining nodes back on the contribution list\X\S$\6
\&{if} $\|c=\\{best\_page\_break}$ \1\&{then}\5
$\\{best\_page\_break}\K\\{null}$;\C{\|c not yet linked in}\2\6
\X1015:Ensure that box 255 is empty before output\X;\6
$\\{insert\_penalties}\K0$;\C{this will count the number of insertions held
over}\6
$\\{save\_split\_top\_skip}\K\\{split\_top\_skip}$;\5
\X1018:Prepare all the boxes involved in insertions to act as queues\X;\6
$\|q\K\\{hold\_head}$;\5
$\\{link}(\|q)\K\\{null}$;\5
$\\{prev\_p}\K\\{page\_head}$;\5
$\|p\K\\{link}(\\{prev\_p})$;\6
\&{while} $\|p\I\\{best\_page\_break}$ \1\&{do}\6
\&{begin} \37\&{if} $\\{type}(\|p)=\\{ins\_node}$ \1\&{then}\5
\X1020:Either insert the material specified by node \|p into the appropriate
box, or hold it for the next page; also delete node \|p from the current page\X%
\6
\4\&{else} \&{if} $\\{type}(\|p)=\\{mark\_node}$ \1\&{then}\5
\X1016:Update the values of \\{first\_mark} and \\{bot\_mark}\X;\2\2\6
$\\{prev\_p}\K\|p$;\5
$\|p\K\\{link}(\\{prev\_p})$;\6
\&{end};\2\6
$\\{split\_top\_skip}\K\\{save\_split\_top\_skip}$;\5
\X1017:Break the current page at node \|p, put it in box~255, and put the
remaining nodes on the contribution list\X;\6
\X1019:Delete the page-insertion nodes\X\par
\U section~1012.\fi

\M1015. \P$\X1015:Ensure that box 255 is empty before output\X\S$\6
\&{if} $\\{box}(255)\I\\{null}$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{""})$;\5
$\\{print\_esc}(\.{"box"})$;\5
$\\{print}(\.{"255\ is\ not\ void"})$;\5
$\\{help2}(\.{"You\ shouldn\'t\ use\ \\box255\ except\ in\ \\output\
routines."})$\6
$(\.{"Proceed,\ and\ I\'ll\ discard\ its\ present\ contents."})$;\5
$\\{box\_error}(255)$;\6
\&{end}\2\par
\U section~1014.\fi

\M1016. \P$\X1016:Update the values of \\{first\_mark} and \\{bot\_mark}\X\S$\6
\&{begin} \37\&{if} $\\{first\_mark}=\\{null}$ \1\&{then}\6
\&{begin} \37$\\{first\_mark}\K\\{mark\_ptr}(\|p)$;\5
$\\{add\_token\_ref}(\\{first\_mark})$;\6
\&{end};\2\6
\&{if} $\\{bot\_mark}\I\\{null}$ \1\&{then}\5
$\\{delete\_token\_ref}(\\{bot\_mark})$;\2\6
$\\{bot\_mark}\K\\{mark\_ptr}(\|p)$;\5
$\\{add\_token\_ref}(\\{bot\_mark})$;\6
\&{end}\par
\U section~1014.\fi

\M1017. When the following code is executed, the current page runs from node
$\\{link}(\\{page\_head})$ to node \\{prev\_p}, and the nodes from \|p to %
\\{page\_tail}
are to be placed back at the front of the contribution list. Furthermore
the heldover insertions appear in a list from $\\{link}(\\{hold\_head})$ to %
\|q; we
will put them into the current page list for safekeeping while the user's
output routine is active.  We might have $\|q=\\{hold\_head}$; and $\|p=%
\\{null}$ if
and only if $\\{prev\_p}=\\{page\_tail}$. Error messages are suppressed within
\\{vpackage}, since the box might appear to be overfull or underfull simply
because the stretch and shrink from the \.{\\skip} registers for inserts
are not actually present in the box.

\Y\P$\4\X1017:Break the current page at node \|p, put it in box~255, and put
the remaining nodes on the contribution list\X\S$\6
\&{if} $\|p\I\\{null}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{link}(\\{contrib\_head})=\\{null}$ \1\&{then}\6
\&{if} $\\{nest\_ptr}=0$ \1\&{then}\5
$\\{tail}\K\\{page\_tail}$\6
\4\&{else} $\\{contrib\_tail}\K\\{page\_tail}$;\2\2\6
$\\{link}(\\{page\_tail})\K\\{link}(\\{contrib\_head})$;\5
$\\{link}(\\{contrib\_head})\K\|p$;\5
$\\{link}(\\{prev\_p})\K\\{null}$;\6
\&{end};\2\6
$\\{save\_vbadness}\K\\{vbadness}$;\5
$\\{vbadness}\K\\{inf\_bad}$;\5
$\\{save\_vfuzz}\K\\{vfuzz}$;\5
$\\{vfuzz}\K\\{max\_dimen}$;\C{inhibit error messages}\6
$\\{box}(255)\K\\{vpackage}(\\{link}(\\{page\_head}),\39\\{best\_size},\39%
\\{exactly},\39\\{page\_max\_depth})$;\5
$\\{vbadness}\K\\{save\_vbadness}$;\5
$\\{vfuzz}\K\\{save\_vfuzz}$;\6
\&{if} $\\{last\_glue}\I\\{max\_halfword}$ \1\&{then}\5
$\\{delete\_glue\_ref}(\\{last\_glue})$;\2\6
\X991:Start a new current page\X;\C{this sets $\\{last\_glue}\K\\{max%
\_halfword}$}\6
\&{if} $\|q\I\\{hold\_head}$ \1\&{then}\6
\&{begin} \37$\\{link}(\\{page\_head})\K\\{link}(\\{hold\_head})$;\5
$\\{page\_tail}\K\|q$;\6
\&{end}\2\par
\U section~1014.\fi

\M1018. If many insertions are supposed to go into the same box, we want to
know
the position of the last node in that box, so that we don't need to waste time
when linking further information into it. The \\{last\_ins\_ptr} fields of the
page insertion nodes are therefore used for this purpose during the
packaging phase.

\Y\P$\4\X1018:Prepare all the boxes involved in insertions to act as queues\X%
\S$\6
$\|r\K\\{link}(\\{page\_ins\_head})$;\6
\&{while} $\|r\I\\{page\_ins\_head}$ \1\&{do}\6
\&{begin} \37\&{if} $\\{best\_ins\_ptr}(\|r)\I\\{null}$ \1\&{then}\6
\&{begin} \37$\|n\K\\{qo}(\\{subtype}(\|r))$;\5
$\\{ensure\_vbox}(\|n)$;\6
\&{if} $\\{box}(\|n)=\\{null}$ \1\&{then}\5
$\\{box}(\|n)\K\\{new\_null\_box}$;\2\6
$\|p\K\\{box}(\|n)+\\{list\_offset}$;\6
\&{while} $\\{link}(\|p)\I\\{null}$ \1\&{do}\5
$\|p\K\\{link}(\|p)$;\2\6
$\\{last\_ins\_ptr}(\|r)\K\|p$;\6
\&{end};\2\6
$\|r\K\\{link}(\|r)$;\6
\&{end}\2\par
\U section~1014.\fi

\M1019. \P$\X1019:Delete the page-insertion nodes\X\S$\6
$\|r\K\\{link}(\\{page\_ins\_head})$;\6
\&{while} $\|r\I\\{page\_ins\_head}$ \1\&{do}\6
\&{begin} \37$\|q\K\\{link}(\|r)$;\5
$\\{free\_node}(\|r,\39\\{page\_ins\_node\_size})$;\5
$\|r\K\|q$;\6
\&{end};\2\6
$\\{link}(\\{page\_ins\_head})\K\\{page\_ins\_head}$\par
\U section~1014.\fi

\M1020. We will set $\\{best\_ins\_ptr}\K\\{null}$ and package the box
corresponding to
insertion node~\|r, just after making the final insertion into that box.
If this final insertion is `\\{split\_up}', the remainder after splitting
and pruning (if any) will be carried over to the next page.

\Y\P$\4\X1020:Either insert the material specified by node \|p into the
appropriate box, or hold it for the next page; also delete node \|p from the
current page\X\S$\6
\&{begin} \37$\|r\K\\{link}(\\{page\_ins\_head})$;\6
\&{while} $\\{subtype}(\|r)\I\\{subtype}(\|p)$ \1\&{do}\5
$\|r\K\\{link}(\|r)$;\2\6
\&{if} $\\{best\_ins\_ptr}(\|r)=\\{null}$ \1\&{then}\5
$\\{wait}\K\\{true}$\6
\4\&{else} \&{begin} \37$\\{wait}\K\\{false}$;\5
$\|s\K\\{ins\_ptr}(\|p)$;\5
$\\{link}(\\{last\_ins\_ptr}(\|r))\K\|s$;\5
$\|s\K\\{last\_ins\_ptr}(\|r)$;\6
\&{if} $\\{best\_ins\_ptr}(\|r)=\|p$ \1\&{then}\5
\X1021:Wrap up the box specified by node \|r, splitting node \|p if called for;
set $\\{wait}\K\\{true}$ if node \|p holds a remainder after splitting\X\6
\4\&{else} \&{begin} \37\&{while} $\\{link}(\|s)\I\\{null}$ \1\&{do}\5
$\|s\K\\{link}(\|s)$;\2\6
$\\{last\_ins\_ptr}(\|r)\K\|s$;\6
\&{end};\2\6
\&{end};\2\6
\X1022:Either append the insertion node \|p after node \|q, and remove it from
the current page, or delete $\\{node}(\|p)$\X;\6
\&{end}\par
\U section~1014.\fi

\M1021. \P$\X1021:Wrap up the box specified by node \|r, splitting node \|p if
called for; set $\\{wait}\K\\{true}$ if node \|p holds a remainder after
splitting\X\S$\6
\&{begin} \37\&{if} $\\{type}(\|r)=\\{split\_up}$ \1\&{then}\6
\&{if} $(\\{broken\_ins}(\|r)=\|p)\W(\\{broken\_ptr}(\|r)\I\\{null})$ \1%
\&{then}\6
\&{begin} \37\&{while} $\\{link}(\|s)\I\\{broken\_ptr}(\|r)$ \1\&{do}\5
$\|s\K\\{link}(\|s)$;\2\6
$\\{split\_top\_skip}\K\\{split\_top\_ptr}(\|p)$;\5
$\\{ins\_ptr}(\|p)\K\\{prune\_page\_top}(\\{broken\_ptr}(\|r))$;\6
\&{if} $\\{ins\_ptr}(\|p)\I\\{null}$ \1\&{then}\6
\&{begin} \37$\\{temp\_ptr}\K\\{vpack}(\\{ins\_ptr}(\|p),\39\\{natural})$;\5
$\\{height}(\|p)\K\\{height}(\\{temp\_ptr})+\\{depth}(\\{temp\_ptr})$;\5
$\\{free\_node}(\\{temp\_ptr},\39\\{box\_node\_size})$;\5
$\\{wait}\K\\{true}$;\6
\&{end};\2\6
$\\{link}(\|s)\K\\{null}$;\6
\&{end};\2\2\6
$\\{best\_ins\_ptr}(\|r)\K\\{null}$;\5
$\|n\K\\{qo}(\\{subtype}(\|r))$;\5
$\\{temp\_ptr}\K\\{list\_ptr}(\\{box}(\|n))$;\5
$\\{free\_node}(\\{box}(\|n),\39\\{box\_node\_size})$;\5
$\\{box}(\|n)\K\\{vpack}(\\{temp\_ptr},\39\\{natural})$;\6
\&{end}\par
\U section~1020.\fi

\M1022. \P$\X1022:Either append the insertion node \|p after node \|q, and
remove it from the current page, or delete $\\{node}(\|p)$\X\S$\6
$\\{link}(\\{prev\_p})\K\\{link}(\|p)$;\5
$\\{link}(\|p)\K\\{null}$;\6
\&{if} $\\{wait}$ \1\&{then}\6
\&{begin} \37$\\{link}(\|q)\K\|p$;\5
$\|q\K\|p$;\5
$\\{incr}(\\{insert\_penalties})$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{delete\_glue\_ref}(\\{split\_top\_ptr}(\|p))$;\5
$\\{free\_node}(\|p,\39\\{ins\_node\_size})$;\6
\&{end};\2\6
$\|p\K\\{prev\_p}$\par
\U section~1020.\fi

\M1023. The list of heldover insertions, running from $\\{link}(\\{page%
\_head})$ to
\\{page\_tail}, must be moved to the contribution list when the user has
specified no output routine.

\Y\P$\4\X1023:Perform the default output routine\X\S$\6
\&{begin} \37\&{if} $\\{link}(\\{page\_head})\I\\{null}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{link}(\\{contrib\_head})=\\{null}$ \1\&{then}\6
\&{if} $\\{nest\_ptr}=0$ \1\&{then}\5
$\\{tail}\K\\{page\_tail}$\ \&{else} $\\{contrib\_tail}\K\\{page\_tail}$\2\6
\4\&{else} $\\{link}(\\{page\_tail})\K\\{link}(\\{contrib\_head})$;\2\6
$\\{link}(\\{contrib\_head})\K\\{link}(\\{page\_head})$;\5
$\\{link}(\\{page\_head})\K\\{null}$;\5
$\\{page\_tail}\K\\{page\_head}$;\6
\&{end};\2\6
$\\{ship\_out}(\\{box}(255))$;\5
$\\{box}(255)\K\\{null}$;\6
\&{end}\par
\U section~1012.\fi

\M1024. \P$\X1024:Explain that too many dead cycles have occurred in a row\X\S$%
\6
\&{begin} \37$\\{print\_err}(\.{"Output\ loop---"})$;\5
$\\{print\_int}(\\{dead\_cycles})$;\5
$\\{print}(\.{"\ consecutive\ dead\ cycles"})$;\5
$\\{help3}(\.{"I\'ve\ concluded\ that\ your\ \\output\ is\ awry;\ it\ never\
does\ a"})$\6
$(\.{"\\shipout,\ so\ I\'m\ shipping\ \\box255\ out\ myself.\ Next\ time"})$\6
$(\.{"increase\ \\maxdeadcycles\ if\ you\ want\ me\ to\ be\ more\ patient!"})$;%
\5
\\{error};\6
\&{end}\par
\U section~1012.\fi

\M1025. \P$\X1025:Fire up the user's output routine and \&{return}\X\S$\6
\&{begin} \37$\\{output\_active}\K\\{true}$;\5
$\\{incr}(\\{dead\_cycles})$;\5
\\{push\_nest};\5
$\\{mode}\K-\\{vmode}$;\5
$\\{prev\_depth}\K\\{ignore\_depth}$;\5
$\\{mode\_line}\K-\\{line}$;\5
$\\{begin\_token\_list}(\\{output\_routine},\39\\{output\_text})$;\5
$\\{new\_save\_level}(\\{output\_group})$;\5
\\{normal\_paragraph};\5
\\{scan\_left\_brace};\5
\&{return};\6
\&{end}\par
\U section~1012.\fi

\M1026. When the user's output routine finishes, it has constructed a vlist
in internal vertical mode, and \TeX\ will do the following:

\Y\P$\4\X1026:Resume the page builder after an output routine has come to an
end\X\S$\6
\&{begin} \37\&{if} $\\{loc}\I\\{null}$ \1\&{then}\5
\X1027:Recover from an unbalanced output routine\X;\2\6
\\{end\_token\_list};\C{conserve stack space in case more outputs are
triggered}\6
\\{end\_graf};\5
\\{unsave};\5
$\\{output\_active}\K\\{false}$;\5
$\\{insert\_penalties}\K0$;\6
\X1028:Ensure that box 255 is empty after output\X;\6
\&{if} $\\{tail}\I\\{head}$ \1\&{then}\C{current list goes after heldover
insertions}\6
\&{begin} \37$\\{link}(\\{page\_tail})\K\\{link}(\\{head})$;\5
$\\{page\_tail}\K\\{tail}$;\6
\&{end};\2\6
\&{if} $\\{link}(\\{page\_head})\I\\{null}$ \1\&{then}\C{and both go before
heldover contributions}\6
\&{begin} \37\&{if} $\\{link}(\\{contrib\_head})=\\{null}$ \1\&{then}\5
$\\{contrib\_tail}\K\\{page\_tail}$;\2\6
$\\{link}(\\{page\_tail})\K\\{link}(\\{contrib\_head})$;\5
$\\{link}(\\{contrib\_head})\K\\{link}(\\{page\_head})$;\5
$\\{link}(\\{page\_head})\K\\{null}$;\5
$\\{page\_tail}\K\\{page\_head}$;\6
\&{end};\2\6
\\{pop\_nest};\5
\\{build\_page};\6
\&{end}\par
\U section~1100.\fi

\M1027. \P$\X1027:Recover from an unbalanced output routine\X\S$\6
\&{begin} \37$\\{print\_err}(\.{"Unbalanced\ output\ routine"})$;\5
$\\{help2}(\.{"Your\ sneaky\ output\ routine\ has\ fewer\ real\ \{\'s\ than\ \}%
\'s."})$\6
$(\.{"I\ can\'t\ handle\ that\ very\ well;\ good\ luck."})$;\5
\\{error};\6
\1\&{repeat} \37\\{get\_token};\6
\4\&{until}\5
$\\{loc}=\\{null}$;\2\6
\&{end}\par
\U section~1026.\fi

\M1028. \P$\X1028:Ensure that box 255 is empty after output\X\S$\6
\&{if} $\\{box}(255)\I\\{null}$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Output\ routine\ didn\'t\ use\ all\ of\ "})$;\5
$\\{print\_esc}(\.{"box"})$;\5
$\\{print\_int}(255)$;\5
$\\{help3}(\.{"Your\ \\output\ commands\ should\ empty\ \\box255,"})$\6
$(\.{"e.g.,\ by\ saying\ \`\\shipout\\box255\'."})$\6
$(\.{"Proceed;\ I\'ll\ discard\ its\ present\ contents."})$;\5
$\\{box\_error}(255)$;\6
\&{end}\2\par
\U section~1026.\fi

\N1029.  \[46] The chief executive.
We come now to the \\{main\_control} routine, which contains the master
switch that causes all the various pieces of \TeX\ to do their things,
in the right order.

In a sense, this is the grand climax of the program: It applies all of the
tools that we have worked so hard to construct. In another sense, this is
the messiest part of the program: It necessarily refers to other pieces
of code all over the place, so that a person can't fully understand what is
going on without paging back and forth to be reminded of conventions that
are defined elsewhere. We are now at the hub of the web, the central nervous
system that touches most of the other parts and ties them together.

The structure of \\{main\_control} itself is quite simple. There's a label
called \\{big\_switch}, at which point the next token of input is fetched
using \\{get\_x\_token}. Then the program branches at high speed into one of
about 100 possible directions, based on the value of the current
mode and the newly fetched command code; the sum $\\{abs}(\\{mode})+\\{cur%
\_cmd}$
indicates what to do next. For example, the case `$\\{vmode}+\\{letter}$'
arises
when a letter occurs in vertical mode (or internal vertical mode); this
case leads to instructions that initialize a new paragraph and enter
horizontal mode.

The big   \&{case}  statement that contains this multiway switch has been
labeled
\\{reswitch}, so that the program can \&{goto} \\{reswitch} when the next token
has already been fetched. Most of the cases are quite short; they call
an ``action procedure'' that does the work for that case, and then they
either \&{goto} \\{reswitch} or they ``fall through'' to the end of the   %
\&{case}
statement, which returns control back to \\{big\_switch}. Thus, \\{main%
\_control}
is not an extremely large procedure, in spite of the multiplicity of things
it must do; it is small enough to be handled by \PASCAL\ compilers that put
severe restrictions on procedure size.

One case is singled out for special treatment, because it accounts for most
of \TeX's activities in typical applications. The process of reading simple
text and converting it into \\{char\_node} records, while looking for ligatures
and kerns, is part of \TeX's ``inner loop''; the whole program runs
efficiently when its inner loop is fast, so this part has been written
with particular care.

\fi

\M1030. We shall concentrate first on the inner loop of \\{main\_control},
deferring
consideration of the other cases until later.

\Y\P\D \37$\\{big\_switch}=60$\C{go here to branch on the next token of input}%
\par
\P\D \37$\\{main\_loop}=70$\C{go here to typeset \\{cur\_chr} in the current
font}\par
\P\D \37$\\{main\_loop\_1}=71$\C{like \\{main\_loop}, but $(\|f,\|c)$ = current
font and char}\par
\P\D \37$\\{main\_loop\_2}=72$\C{like \\{main\_loop\_1}, but \|c is known to be
in range}\par
\P\D \37$\\{main\_loop\_3}=73$\C{like \\{main\_loop\_2}, but several variables
are set up}\par
\P\D \37$\\{append\_normal\_space}=74$\C{go here to append a normal space
between words}\par
\Y\P\hbox{\4}\X1043:Declare action procedures for use by \\{main\_control}\X\6
\hbox{\4}\X1068\*:Declare the procedure called \\{handle\_right\_brace}\X\6
\4\&{procedure}\1\  \37\\{main\_control};\C{governs \TeX's activities}\6
\4\&{label} \37$\\{big\_switch},\39\\{reswitch},\39\\{main\_loop},\39\\{main%
\_loop\_1},\39\\{main\_loop\_2},\39\\{main\_loop\_3},\39\\{append\_normal%
\_space},\39\\{exit}$;\6
\4\&{var} \37\|t: \37\\{integer};\C{general-purpose temporary variable}\6
\X1032:Local variables for the inner loop of \\{main\_control}\X\2\6
\&{begin} \37\&{if} $\\{every\_job}\I\\{null}$ \1\&{then}\5
$\\{begin\_token\_list}(\\{every\_job},\39\\{every\_job\_text})$;\2\6
\4\\{big\_switch}: \37\\{get\_x\_token};\6
\4\\{reswitch}: \37\X1031:Give diagnostic information, if requested\X;\6
\&{case} $\\{abs}(\\{mode})+\\{cur\_cmd}$ \1\&{of}\6
\4$\\{hmode}+\\{letter},\39\\{hmode}+\\{other\_char},\39\\{hmode}+\\{char%
\_given}$: \37\&{goto} \37\\{main\_loop};\6
\4$\\{hmode}+\\{char\_num}$: \37\&{begin} \37\\{scan\_char\_num};\5
$\\{cur\_chr}\K\\{cur\_val}$;\5
\&{goto} \37\\{main\_loop};\6
\&{end};\6
\4$\\{hmode}+\\{spacer}$: \37\&{if} $\\{space\_factor}=1000$ \1\&{then}\5
\&{goto} \37\\{append\_normal\_space}\6
\4\&{else} \\{app\_space};\2\6
\4$\\{hmode}+\\{ex\_space},\39\\{mmode}+\\{ex\_space}$: \37\&{goto} \37%
\\{append\_normal\_space};\6
\hbox{\4}\X1045:Cases of \\{main\_control} that are not part of the inner loop%
\X\2\6
\&{end};\C{of the big   \&{case}  statement}\6
\&{goto} \37\\{big\_switch};\6
\4\\{main\_loop}: \37\X1033:Append character \\{cur\_chr} and the following
characters (if~any) to the current hlist in the current font; \&{goto} %
\\{reswitch} when a non-character has been fetched\X;\6
\4\\{append\_normal\_space}: \37\X1041:Append a normal inter-word space to the
current list, then \&{goto} \\{big\_switch}\X;\6
\4\\{exit}: \37\&{end};\par
\fi

\M1031. When a new token has just been fetched at \\{big\_switch}, we have an
ideal place to monitor \TeX's activity.

\Y\P$\4\X1031:Give diagnostic information, if requested\X\S$\6
\&{if} $\\{interrupt}\I0$ \1\&{then}\6
\&{if} $\\{OK\_to\_interrupt}$ \1\&{then}\6
\&{begin} \37\\{back\_input};\5
\\{check\_interrupt};\5
\&{goto} \37\\{big\_switch};\6
\&{end};\2\2\6
\&{debug} \37\&{if} $\\{panicking}$ \1\&{then}\5
$\\{check\_mem}(\\{false})$;\ \2\ \&{gubed}\6
\&{if} $\\{tracing\_commands}>0$ \1\&{then}\5
\\{show\_cur\_cmd\_chr}\2\par
\U section~1030.\fi

\M1032. In the following program, \|l is the current character or ligature;
it might grow into a longer ligature. One or more characters has been
used to define \|l, and the last of these was \|c. The chief use of \|c
will be to modify \\{space\_factor} and to insert discretionary nodes after
explicit hyphens in the text.

\Y\P$\4\X1032:Local variables for the inner loop of \\{main\_control}\X\S$\6
\4\|l: \37\\{quarterword};\C{the current character or ligature}\6
\4\|c: \37\\{eight\_bits};\C{the most recent character}\6
\4\|f: \37\\{internal\_font\_number};\C{the current font}\6
\4\|r: \37\\{halfword};\C{the next character for ligature/kern matching}\6
\4\|p: \37\\{pointer};\C{the current \\{char\_node}}\6
\4\|k: \37$0\to\\{font\_mem\_size}$;\C{index into \\{font\_info}}\6
\4\|q: \37\\{pointer};\C{where a ligature should be detached}\6
\4\|i: \37\\{four\_quarters};\C{character information bytes for \|l}\6
\4\|j: \37\\{four\_quarters};\C{ligature/kern command}\6
\4\|s: \37\\{integer};\C{space factor code}\6
\4\\{ligature\_present}: \37\\{boolean};\C{should a ligature node be made?}\par
\U section~1030.\fi

\M1033. \P$\X1033:Append character \\{cur\_chr} and the following characters
(if~any) to the current hlist in the current font; \&{goto} \\{reswitch} when a
non-character has been fetched\X\S$\6
$\|f\K\\{cur\_font}$;\5
$\|c\K\\{cur\_chr}$;\6
\4\\{main\_loop\_1}: \37\&{if} $(\|c<\\{font\_bc}[\|f])\V(\|c>\\{font\_ec}[%
\|f])$ \1\&{then}\6
\&{begin} \37$\\{char\_warning}(\|f,\39\|c)$;\5
\&{goto} \37\\{big\_switch};\6
\&{end};\2\6
\4\\{main\_loop\_2}: \37$\|q\K\\{tail}$;\5
$\\{ligature\_present}\K\\{false}$;\5
$\|l\K\\{qi}(\|c)$;\6
\4\\{main\_loop\_3}: \37\X1034:Adjust \(t)the space factor, based on its
current value and \|c\X;\6
\X1035:Append character \|l and the following characters (if any) to the
current hlist, in font \|f; if \\{ligature\_present}, detach a ligature node
starting at $\\{link}(\|q)$; if \|c is a hyphen, append a null \\{disc\_node};
finally \&{goto} \\{reswitch}\X\par
\U section~1030.\fi

\M1034. We leave \\{space\_factor} unchanged if $\\{sf\_code}(\|c)=0$;
otherwise we set it
to $\\{sf\_code}(\|c)$, except that the space factor never changes from a value
less than 1000 to a value exceeding 1000. If $\|c\G128$, its \\{sf\_code} is
implicitly 1000. The most common case is $\\{sf\_code}(\|c)=1000$, so we want
that case to be fast.

\Y\P$\4\X1034:Adjust \(t)the space factor, based on its current value and \|c\X%
\S$\6
\&{if} $\|c<128$ \1\&{then}\6
\&{begin} \37$\|s\K\\{sf\_code}(\|c)$;\6
\&{if} $\|s=1000$ \1\&{then}\5
$\\{space\_factor}\K1000$\6
\4\&{else} \&{if} $\|s<1000$ \1\&{then}\6
\&{begin} \37\&{if} $\|s>0$ \1\&{then}\5
$\\{space\_factor}\K\|s$;\2\6
\&{end}\6
\4\&{else} \&{if} $\\{space\_factor}<1000$ \1\&{then}\5
$\\{space\_factor}\K1000$\6
\4\&{else} $\\{space\_factor}\K\|s$;\2\2\2\6
\&{end}\6
\4\&{else} $\\{space\_factor}\K1000$\2\par
\U section~1033.\fi

\M1035. Now we come to the inner loop, in which the characters of a word are
gathered at (hopefully) high speed.

\Y\P$\4\X1035:Append character \|l and the following characters (if any) to the
current hlist, in font \|f; if \\{ligature\_present}, detach a ligature node
starting at $\\{link}(\|q)$; if \|c is a hyphen, append a null \\{disc\_node};
finally \&{goto} \\{reswitch}\X\S$\6
$\|i\K\\{char\_info}(\|f)(\|l)$;\6
\&{if} $\\{char\_exists}(\|i)$ \1\&{then}\6
\&{begin} \37$\\{fast\_get\_avail}(\|p)$;\5
$\\{font}(\|p)\K\|f$;\5
$\\{character}(\|p)\K\\{qi}(\|c)$;\5
$\\{link}(\\{tail})\K\|p$;\5
$\\{tail}\K\|p$;\6
\&{end}\6
\4\&{else} $\\{char\_warning}(\|f,\39\\{qo}(\|l))$;\2\6
\X1036:Look ahead for ligature or kerning, either continuing the main loop or
going to \\{reswitch}\X\par
\U section~1033.\fi

\M1036. The result of \.{\\char} can participate in a ligature or kern, so
we must look ahead for it.

\Y\P$\4\X1036:Look ahead for ligature or kerning, either continuing the main
loop or going to \\{reswitch}\X\S$\6
\\{get\_next};\C{set only \\{cur\_cmd} and \\{cur\_chr}}\6
\&{if} $\\{cur\_cmd}=\\{letter}$ \1\&{then}\5
$\|r\K\\{qi}(\\{cur\_chr})$\6
\4\&{else} \&{if} $\\{cur\_cmd}=\\{other\_char}$ \1\&{then}\5
$\|r\K\\{qi}(\\{cur\_chr})$\6
\4\&{else} \&{if} $\\{cur\_cmd}=\\{char\_given}$ \1\&{then}\5
$\|r\K\\{qi}(\\{cur\_chr})$\6
\4\&{else} \&{begin} \37\\{x\_token};\C{set \\{cur\_cmd}, \\{cur\_chr}, \\{cur%
\_tok}}\6
\&{if} $(\\{cur\_cmd}=\\{letter})\V(\\{cur\_cmd}=\\{other\_char})\V(\\{cur%
\_cmd}=\\{char\_given})$ \1\&{then}\5
$\|r\K\\{qi}(\\{cur\_chr})$\6
\4\&{else} \&{if} $\\{cur\_cmd}=\\{char\_num}$ \1\&{then}\6
\&{begin} \37\\{scan\_char\_num};\5
$\|r\K\\{qi}(\\{cur\_val})$;\6
\&{end}\6
\4\&{else} $\|r\K\\{qi}(256)$;\C{this flag means that no character follows}\2\2%
\6
\&{end};\2\2\2\6
\&{if} $\\{char\_tag}(\|i)=\\{lig\_tag}$ \1\&{then}\6
\&{if} $\|r\I\\{qi}(256)$ \1\&{then}\5
\X1037:Follow the lig/kern program; \&{goto} \\{main\_loop\_3} if scoring a hit%
\X;\2\2\6
\X1039:Make a ligature node, if \\{ligature\_present}; insert a discretionary
node for an explicit hyphen, if \|c is the current \\{hyphen\_char}\X;\6
\&{if} $\|r=\\{qi}(256)$ \1\&{then}\5
\&{goto} \37\\{reswitch};\C{\\{cur\_cmd}, \\{cur\_chr}, \\{cur\_tok} are
untouched}\2\6
$\|c\K\\{qo}(\|r)$;\5
\&{goto} \37\\{main\_loop\_1}\C{\|f is still valid}\par
\U section~1035.\fi

\M1037. Even though comparatively few characters have a lig/kern program, the  %
\&{repeat}
construction here counts as part of \TeX's inner loop, since it involves a
potentially long sequential search. For example, tests with one commonly
used font showed that about 40 per cent of all characters had a lig/kern
program, and the  \&{repeat}  loop was performed about four times for every
such character.

\Y\P$\4\X1037:Follow the lig/kern program; \&{goto} \\{main\_loop\_3} if
scoring a hit\X\S$\6
\&{begin} \37$\|k\K\\{lig\_kern\_start}(\|f)(\|i)$;\6
\1\&{repeat} \37$\|j\K\\{font\_info}[\|k].\\{qqqq}$;\C{fetch a lig/kern
command}\6
\&{if} $\\{next\_char}(\|j)=\|r$ \1\&{then}\6
\&{if} $\\{op\_bit}(\|j)<\\{kern\_flag}$ \1\&{then}\5
\X1040:Extend a ligature, \&{goto} \\{main\_loop\_3}\X\6
\4\&{else} \X1038:Append a kern, \&{goto} \\{main\_loop\_2}\X;\2\2\6
$\\{incr}(\|k)$;\6
\4\&{until}\5
$\\{stop\_bit}(\|j)\G\\{stop\_flag}$;\2\6
\&{end}\par
\U section~1036.\fi

\M1038. \P$\X1038:Append a kern, \&{goto} \\{main\_loop\_2}\X\S$\6
\&{begin} \37\X1039:Make a ligature node, if \\{ligature\_present}; insert a
discretionary node for an explicit hyphen, if \|c is the current \\{hyphen%
\_char}\X;\6
$\\{tail\_append}(\\{new\_kern}(\\{char\_kern}(\|f)(\|j)))$;\5
$\|c\K\\{qo}(\|r)$;\5
\&{goto} \37\\{main\_loop\_2};\6
\&{end}\par
\U section~1037.\fi

\M1039. A discretionary break is not inserted for an explicit hyphen when we
are
in restricted horizontal mode. In particular, this avoids putting
discretionary nodes inside of other discretionaries.

\Y\P$\4\X1039:Make a ligature node, if \\{ligature\_present}; insert a
discretionary node for an explicit hyphen, if \|c is the current \\{hyphen%
\_char}\X\S$\6
\&{if} $\\{ligature\_present}$ \1\&{then}\6
\&{begin} \37$\|p\K\\{new\_ligature}(\|f,\39\|l,\39\\{link}(\|q))$;\5
$\\{link}(\|q)\K\|p$;\5
$\\{tail}\K\|p$;\6
\&{end};\2\6
\&{if} $\|c=\\{hyphen\_char}[\|f]$ \1\&{then}\6
\&{if} $\\{mode}=\\{hmode}$ \1\&{then}\5
$\\{tail\_append}(\\{new\_disc})$\2\2\par
\U sections~1036 and~1038.\fi

\M1040. \P$\X1040:Extend a ligature, \&{goto} \\{main\_loop\_3}\X\S$\6
\&{begin} \37$\\{ligature\_present}\K\\{true}$;\5
$\|l\K\\{rem\_byte}(\|j)$;\5
$\|c\K\\{qo}(\|r)$;\5
\&{goto} \37\\{main\_loop\_3};\6
\&{end}\par
\U section~1037.\fi

\M1041. The occurrence of blank spaces is almost part of \TeX's inner loop,
since we usually encounter about one space for every five non-blank characters.
Therefore \\{main\_control} gives second-highest priority to ordinary spaces.

When a glue parameter like \.{\\spaceskip} is set to `\.{0pt}', we will
see to it later that the corresponding glue specification is precisely
\\{zero\_glue}, not merely a pointer to some other specification that happens
to be full of zeroes. Therefore it is simple to test whether a glue parameter
is zero or not.

\Y\P$\4\X1041:Append a normal inter-word space to the current list, then %
\&{goto} \\{big\_switch}\X\S$\6
\&{if} $\\{space\_skip}=\\{zero\_glue}$ \1\&{then}\6
\&{begin} \37\X1042:Find the glue specification, \|p, for text spaces in the
current font\X;\6
$\|q\K\\{new\_glue}(\|p)$;\6
\&{end}\6
\4\&{else} $\|q\K\\{new\_param\_glue}(\\{space\_skip\_code})$;\2\6
$\\{link}(\\{tail})\K\|q$;\5
$\\{tail}\K\|q$;\5
\&{goto} \37\\{big\_switch}\par
\U section~1030.\fi

\M1042. Having \\{font\_glue} allocated for each text font saves both time and
memory.
If any of the three spacing parameters are subsequently changed by the
use of \.{\\fontdimen}, the \\{find\_font\_dimen} procedure deallocates the
\\{font\_glue} specification allocated here.

\Y\P$\4\X1042:Find the glue specification, \|p, for text spaces in the current
font\X\S$\6
\&{begin} \37$\|p\K\\{font\_glue}[\\{cur\_font}]$;\6
\&{if} $\|p=\\{null}$ \1\&{then}\6
\&{begin} \37$\|f\K\\{cur\_font}$;\5
$\|p\K\\{new\_spec}(\\{zero\_glue})$;\5
$\|k\K\\{param\_base}[\|f]+\\{space\_code}$;\5
$\\{width}(\|p)\K\\{font\_info}[\|k].\\{sc}$;\C{that's $\\{space}(\|f)$}\6
$\\{stretch}(\|p)\K\\{font\_info}[\|k+1].\\{sc}$;\C{and $\\{space\_stretch}(%
\|f)$}\6
$\\{shrink}(\|p)\K\\{font\_info}[\|k+2].\\{sc}$;\C{and $\\{space\_shrink}(%
\|f)$}\6
$\\{font\_glue}[\|f]\K\|p$;\6
\&{end};\2\6
\&{end}\par
\U sections~1041 and~1043.\fi

\M1043. \P$\X1043:Declare action procedures for use by \\{main\_control}\X\S$\6
\4\&{procedure}\1\  \37\\{app\_space};\C{handle spaces when $\\{space\_factor}%
\I1000$}\6
\4\&{var} \37\|p: \37\\{pointer};\C{glue specification}\6
\|q: \37\\{pointer};\C{glue node}\6
\|f: \37\\{internal\_font\_number};\C{the current font}\6
\|k: \37$0\to\\{font\_mem\_size}$;\C{index into \\{font\_info}}\2\6
\&{begin} \37\&{if} $(\\{space\_factor}\G2000)\W(\\{xspace\_skip}\I\\{zero%
\_glue})$ \1\&{then}\5
$\|q\K\\{new\_param\_glue}(\\{xspace\_skip\_code})$\6
\4\&{else} \&{begin} \37\&{if} $\\{space\_skip}\I\\{zero\_glue}$ \1\&{then}\5
$\|p\K\\{space\_skip}$\6
\4\&{else} \X1042:Find the glue specification, \|p, for text spaces in the
current font\X;\2\6
$\|p\K\\{new\_spec}(\|p)$;\5
\X1044:Modify the glue specification in \|p according to the space factor\X;\6
$\|q\K\\{new\_glue}(\|p)$;\5
$\\{glue\_ref\_count}(\|p)\K\\{null}$;\6
\&{end};\2\6
$\\{link}(\\{tail})\K\|q$;\5
$\\{tail}\K\|q$;\6
\&{end};\par
\A sections~1047, 1049, 1050, 1051, 1054, 1060, 1061, 1064, 1069, 1070, 1075,
1079, 1084, 1086, 1091, 1093, 1095, 1096, 1099, 1101, 1103, 1105, 1110, 1113,
1117, 1119, 1123, 1127, 1129, 1131, 1135, 1136, 1138, 1142, 1151, 1155, 1159,
1160, 1163, 1165, 1172, 1174, 1176, 1181, 1191, 1194, 1200, 1211, 1270, 1275,
1279, 1288, 1293, 1302, and~1348.
\U section~1030.\fi

\M1044. \P$\X1044:Modify the glue specification in \|p according to the space
factor\X\S$\6
\&{if} $\\{space\_factor}\G2000$ \1\&{then}\5
$\\{width}(\|p)\K\\{width}(\|p)+\\{extra\_space}(\\{cur\_font})$;\2\6
$\\{stretch}(\|p)\K\\{xn\_over\_d}(\\{stretch}(\|p),\39\\{space\_factor},%
\391000)$;\5
$\\{shrink}(\|p)\K\\{xn\_over\_d}(\\{shrink}(\|p),\391000,\39\\{space%
\_factor})$\par
\U section~1043.\fi

\M1045. Whew---that covers the main loop. We can now proceed at a leisurely
pace through the other combinations of possibilities.

\Y\P\D \37$\\{any\_mode}(\#)\S\\{vmode}+\#,\39\\{hmode}+\#,\39\\{mmode}+\#$%
\C{for mode-independent commands}\par
\Y\P$\4\X1045:Cases of \\{main\_control} that are not part of the inner loop\X%
\S$\6
\4$\\{any\_mode}(\\{relax}),\39\\{vmode}+\\{spacer},\39\\{mmode}+\\{spacer}$: %
\37\\{do\_nothing};\6
\4$\\{any\_mode}(\\{ignore\_spaces})$: \37\&{begin} \37\X406:Get the next
non-blank non-call token\X;\6
\&{goto} \37\\{reswitch};\6
\&{end};\6
\4$\\{vmode}+\\{stop}$: \37\&{if} $\\{its\_all\_over}$ \1\&{then}\5
\&{return};\C{this is the only way out}\2\6
\hbox{\4}\X1048:Forbidden cases detected in \\{main\_control}\X\ $\,\\{any%
\_mode}(\\{mac\_param})$: \37\\{report\_illegal\_case};\6
\4\X1046\*:Math-only cases in non-math modes, or vice versa\X: \37\\{insert%
\_dollar\_sign};\5
\hbox{\4}\X1056:Cases of \\{main\_control} that build boxes and lists\X\6
\hbox{\4}\X1210:Cases of \\{main\_control} that don't depend on \\{mode}\X\6
\hbox{\4}\X1347:Cases of \\{main\_control} that are for extensions to \TeX\X\par
\U section~1030.\fi

\M1046\*. Here is a list of cases where the user has probably gotten into or
out of math
mode by mistake. \TeX\ will insert a dollar sign and rescan the current token.

\Y\P\D \37$\\{non\_math}(\#)\S\\{vmode}+\#,\39\\{hmode}+\#$\par
\Y\P$\4\X1046\*:Math-only cases in non-math modes, or vice versa\X\S$\6
$\\{non\_math}(\\{sup\_mark}),\39\\{non\_math}(\\{sub\_mark}),\39\\{non\_math}(%
\\{math\_char\_num}),\39\\{non\_math}(\\{math\_given}),\39\\{non\_math}(\\{math%
\_comp}),\39\\{non\_math}(\\{delim\_num}),\39\\{non\_math}(\\{left\_right}),\39%
\\{non\_math}(\\{above}),\39\\{non\_math}(\\{radical}),\39\\{non\_math}(\\{math%
\_style}),\39\\{non\_math}(\\{math\_choice}),\39\\{non\_math}(\\{vcenter}),\39%
\\{non\_math}(\\{non\_script}),\39\\{non\_math}(\\{mkern}),\39\\{non\_math}(%
\\{limit\_switch}),\39\\{non\_math}(\\{mskip}),\39\\{non\_math}(\\{math%
\_accent}),\39\\{mmode}+\\{endv},\39\\{mmode}+\\{par\_end},\39\\{mmode}+%
\\{xchar\_num},\39\\{mmode}+\\{stop},\39\\{mmode}+\\{vskip},\39\\{mmode}+\\{un%
\_vbox},\39\\{mmode}+\\{valign},\39\\{mmode}+\\{hrule}$\par
\U section~1045.\fi

\M1047. \P$\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{insert\_dollar\_sign};\2\6
\&{begin} \37\\{back\_input};\5
$\\{cur\_tok}\K\\{math\_shift\_token}+\.{"\$"}$;\5
$\\{print\_err}(\.{"Missing\ \$\ inserted"})$;\5
$\\{help2}(\.{"I\'ve\ inserted\ a\ begin-math/end-math\ symbol\ since\ I\
think"})$\6
$(\.{"you\ left\ one\ out.\ Proceed,\ with\ fingers\ crossed."})$;\5
\\{ins\_error};\6
\&{end};\par
\fi

\M1048. When erroneous situations arise, \TeX\ usually issues an error message
specific to the particular error. For example, `\.{\\noalign}' should
not appear in any mode, since it is recognized by the \\{align\_peek} routine
in all of its legitimate appearances; a special error message is given
when `\.{\\noalign}' occurs elsewhere. But sometimes the most appropriate
error message is simply that the user is not allowed to do what he or she
has attempted. For example, `\.{\\moveleft}' is allowed only in vertical mode,
and `\.{\\lower}' only in non-vertical modes.  Such cases are enumerated
here and in the other sections referred to under `See also \dots.'

\Y\P$\4\X1048:Forbidden cases detected in \\{main\_control}\X\S$\6
$\\{vmode}+\\{vmove},\39\\{hmode}+\\{hmove},\39\\{mmode}+\\{hmove},\39\\{any%
\_mode}(\\{last\_item}),\39$\par
\A sections~1098, 1111, and~1144.
\U section~1045.\fi

\M1049. The `\\{you\_cant}' procedure prints a line saying that the current
command
is illegal in the current mode; it identifies these things symbolically.

\Y\P$\4\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{you\_cant};\2\6
\&{begin} \37$\\{print\_err}(\.{"You\ can\'t\ use\ \`"})$;\5
$\\{print\_cmd\_chr}(\\{cur\_cmd},\39\\{cur\_chr})$;\5
$\\{print}(\.{"\'\ in\ "})$;\5
$\\{print\_mode}(\\{mode})$;\6
\&{end};\par
\fi

\M1050. \P$\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{report\_illegal\_case};\2\6
\&{begin} \37\\{you\_cant};\5
$\\{help4}(\.{"Sorry,\ but\ I\'m\ not\ programmed\ to\ handle\ this\ case;"})$\6
$(\.{"I\'ll\ just\ pretend\ that\ you\ didn\'t\ ask\ for\ it."})$\6
$(\.{"If\ you\'re\ in\ the\ wrong\ mode,\ you\ might\ be\ able\ to"})$\6
$(\.{"return\ to\ the\ right\ one\ by\ typing\ \`I\}\'\ or\ \`I\$\'\ or\ \`I%
\\par\'."})$;\6
\\{error};\6
\&{end};\par
\fi

\M1051. Some operations are allowed only in privileged modes, i.e., in cases
that $\\{mode}>0$. The \\{privileged} function is used to detect violations
of this rule; it issues an error message and returns \\{false} if the
current \\{mode} is negative.

\Y\P$\4\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{function}\1\  \37\\{privileged}: \37\\{boolean};\2\6
\&{begin} \37\&{if} $\\{mode}>0$ \1\&{then}\5
$\\{privileged}\K\\{true}$\6
\4\&{else} \&{begin} \37\\{report\_illegal\_case};\5
$\\{privileged}\K\\{false}$;\6
\&{end};\2\6
\&{end};\par
\fi

\M1052. Either \.{\\dump} or \.{\\end} will cause \\{main\_control} to enter
the
endgame, since both of them have `\\{stop}' as their command code.

\Y\P$\4\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}\S$\6
$\\{primitive}(\.{"end"},\39\\{stop},\390)$;\6
$\\{primitive}(\.{"dump"},\39\\{stop},\391)$;\par
\fi

\M1053. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{stop}: \37\&{if} $\\{chr\_code}=1$ \1\&{then}\5
$\\{print\_esc}(\.{"dump"})$\ \&{else} $\\{print\_esc}(\.{"end"})$;\2\par
\fi

\M1054. We don't want to leave \\{main\_control} immediately when a \\{stop}
command
is sensed, because it may be necessary to invoke an \.{\\output} routine
several times before things really grind to a halt. (The output routine
might even say `\.{\\gdef\\end\{...\}}', to prolong the life of the job.)
Therefore \\{its\_all\_over} is \\{true} only when the current page
and contribution list are empty, and when the last output was not a
``dead cycle.''

\Y\P$\4\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{function}\1\  \37\\{its\_all\_over}: \37\\{boolean};\C{do this when \.{%
\\end} or \.{\\dump} occurs}\6
\4\&{label} \37\\{exit};\2\6
\&{begin} \37\&{if} $\\{privileged}$ \1\&{then}\6
\&{begin} \37\&{if} $(\\{page\_head}=\\{page\_tail})\W(\\{head}=\\{tail})\W(%
\\{dead\_cycles}=0)$ \1\&{then}\6
\&{begin} \37$\\{its\_all\_over}\K\\{true}$;\5
\&{return};\6
\&{end};\2\6
\\{back\_input};\C{we will try to end again after ejecting residual material}\6
$\\{tail\_append}(\\{new\_null\_box})$;\5
$\\{width}(\\{tail})\K\\{hsize}$;\5
$\\{tail\_append}(\\{new\_glue}(\\{fill\_glue}))$;\5
$\\{tail\_append}(\\{new\_penalty}(-\O{10000000000}))$;\6
\\{build\_page};\C{append \.{\\hbox to \\hsize\{\}\\vss\\penalty-'10000000000}}%
\6
\&{end};\2\6
$\\{its\_all\_over}\K\\{false}$;\6
\4\\{exit}: \37\&{end};\par
\fi

\N1055.  \[47] Building boxes and lists.
The most important parts of \\{main\_control} are concerned with \TeX's
chief mission of box-making. We need to control the activities that put
entries on vlists and hlists, as well as the activities that convert
those lists into boxes. All of the necessary machinery has already been
developed; it remains for us to ``push the buttons'' at the right times.

\fi

\M1056. As an introduction to these routines, let's consider one of the
simplest
cases: What happens when `\.{\\hrule}' occurs in vertical mode, or
`\.{\\vrule}' in horizontal mode or math mode? The code in \\{main\_control}
is short, since the \\{scan\_rule\_spec} routine already does most of what is
required; thus, there is no need for a special action procedure.

Note that baselineskip calculations are disabled after a rule in vertical
mode, by setting $\\{prev\_depth}\K\\{ignore\_depth}$.

\Y\P$\4\X1056:Cases of \\{main\_control} that build boxes and lists\X\S$\6
\4$\\{vmode}+\\{hrule},\39\\{hmode}+\\{vrule},\39\\{mmode}+\\{vrule}$: \37%
\&{begin} \37$\\{tail\_append}(\\{scan\_rule\_spec})$;\6
\&{if} $\\{abs}(\\{mode})=\\{vmode}$ \1\&{then}\5
$\\{prev\_depth}\K\\{ignore\_depth}$\6
\4\&{else} \&{if} $\\{abs}(\\{mode})=\\{hmode}$ \1\&{then}\5
$\\{space\_factor}\K1000$;\2\2\6
\&{end};\par
\A sections~1057, 1063\*, 1067, 1073, 1090\*, 1092, 1094, 1097, 1102, 1104,
1109, 1112, 1116, 1122\*, 1126, 1130, 1134, 1137, 1140, 1150, 1154, 1158, 1162,
1164, 1167, 1171, 1175, 1180, 1190, and~1193.
\U section~1045.\fi

\M1057. The processing of things like \.{\\hskip} and \.{\\vskip} is slightly
more complicated. But the code in \\{main\_control} is very short, since
it simply calls on the action routine \\{append\_glue}. Similarly, \.{\\kern}
activates \\{append\_kern}.

\Y\P$\4\X1056:Cases of \\{main\_control} that build boxes and lists\X%
\mathrel{+}\S$\6
\4$\\{vmode}+\\{vskip},\39\\{hmode}+\\{hskip},\39\\{mmode}+\\{hskip},\39%
\\{mmode}+\\{mskip}$: \37\\{append\_glue};\6
\4$\\{any\_mode}(\\{kern}),\39\\{mmode}+\\{mkern}$: \37\\{append\_kern};\par
\fi

\M1058. The \\{hskip} and \\{vskip} command codes are used for control
sequences
like \.{\\hss} and \.{\\vfil} as well as for \.{\\hskip} and \.{\\vskip}.
The difference is in the value of \\{cur\_chr}.

\Y\P\D \37$\\{fil\_code}=0$\C{identifies \.{\\hfil} and \.{\\vfil}}\par
\P\D \37$\\{fill\_code}=1$\C{identifies \.{\\hfill} and \.{\\vfill}}\par
\P\D \37$\\{ss\_code}=2$\C{identifies \.{\\hss} and \.{\\vss}}\par
\P\D \37$\\{fil\_neg\_code}=3$\C{identifies \.{\\hfilneg} and \.{\\vfilneg}}\par
\P\D \37$\\{skip\_code}=4$\C{identifies \.{\\hskip} and \.{\\vskip}}\par
\P\D \37$\\{mskip\_code}=5$\C{identifies \.{\\mskip}}\par
\Y\P$\4\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}\S$\6
$\\{primitive}(\.{"hskip"},\39\\{hskip},\39\\{skip\_code})$;\6
$\\{primitive}(\.{"hfil"},\39\\{hskip},\39\\{fil\_code})$;\5
$\\{primitive}(\.{"hfill"},\39\\{hskip},\39\\{fill\_code})$;\6
$\\{primitive}(\.{"hss"},\39\\{hskip},\39\\{ss\_code})$;\5
$\\{primitive}(\.{"hfilneg"},\39\\{hskip},\39\\{fil\_neg\_code})$;\6
$\\{primitive}(\.{"vskip"},\39\\{vskip},\39\\{skip\_code})$;\6
$\\{primitive}(\.{"vfil"},\39\\{vskip},\39\\{fil\_code})$;\5
$\\{primitive}(\.{"vfill"},\39\\{vskip},\39\\{fill\_code})$;\6
$\\{primitive}(\.{"vss"},\39\\{vskip},\39\\{ss\_code})$;\5
$\\{primitive}(\.{"vfilneg"},\39\\{vskip},\39\\{fil\_neg\_code})$;\6
$\\{primitive}(\.{"mskip"},\39\\{mskip},\39\\{mskip\_code})$;\6
$\\{primitive}(\.{"kern"},\39\\{kern},\39\\{explicit})$;\5
$\\{primitive}(\.{"mkern"},\39\\{mkern},\39\\{mu\_glue})$;\par
\fi

\M1059. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{hskip}: \37\&{case} $\\{chr\_code}$ \1\&{of}\6
\4\\{skip\_code}: \37$\\{print\_esc}(\.{"hskip"})$;\6
\4\\{fil\_code}: \37$\\{print\_esc}(\.{"hfil"})$;\6
\4\\{fill\_code}: \37$\\{print\_esc}(\.{"hfill"})$;\6
\4\\{ss\_code}: \37$\\{print\_esc}(\.{"hss"})$;\6
\4\&{othercases} \37$\\{print\_esc}(\.{"hfilneg"})$\2\6
\&{endcases};\6
\4\\{vskip}: \37\&{case} $\\{chr\_code}$ \1\&{of}\6
\4\\{skip\_code}: \37$\\{print\_esc}(\.{"vskip"})$;\6
\4\\{fil\_code}: \37$\\{print\_esc}(\.{"vfil"})$;\6
\4\\{fill\_code}: \37$\\{print\_esc}(\.{"vfill"})$;\6
\4\\{ss\_code}: \37$\\{print\_esc}(\.{"vss"})$;\6
\4\&{othercases} \37$\\{print\_esc}(\.{"vfilneg"})$\2\6
\&{endcases};\6
\4\\{mskip}: \37$\\{print\_esc}(\.{"mskip"})$;\6
\4\\{kern}: \37$\\{print\_esc}(\.{"kern"})$;\6
\4\\{mkern}: \37$\\{print\_esc}(\.{"mkern"})$;\par
\fi

\M1060. All the work relating to glue creation has been relegated to the
following subroutine. It does not call \\{build\_page}, because it is
used in at least one place where that would be a mistake.

\Y\P$\4\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{append\_glue};\6
\4\&{var} \37\|s: \37\\{small\_number};\C{modifier of skip command}\2\6
\&{begin} \37$\|s\K\\{cur\_chr}$;\6
\&{case} $\|s$ \1\&{of}\6
\4\\{fil\_code}: \37$\\{cur\_val}\K\\{fil\_glue}$;\6
\4\\{fill\_code}: \37$\\{cur\_val}\K\\{fill\_glue}$;\6
\4\\{ss\_code}: \37$\\{cur\_val}\K\\{ss\_glue}$;\6
\4\\{fil\_neg\_code}: \37$\\{cur\_val}\K\\{fil\_neg\_glue}$;\6
\4\\{skip\_code}: \37$\\{scan\_glue}(\\{glue\_val})$;\6
\4\\{mskip\_code}: \37$\\{scan\_glue}(\\{mu\_val})$;\2\6
\&{end};\C{now \\{cur\_val} points to the glue specification}\6
$\\{tail\_append}(\\{new\_glue}(\\{cur\_val}))$;\6
\&{if} $\|s\G\\{skip\_code}$ \1\&{then}\6
\&{begin} \37$\\{decr}(\\{glue\_ref\_count}(\\{cur\_val}))$;\6
\&{if} $\|s>\\{skip\_code}$ \1\&{then}\5
$\\{subtype}(\\{tail})\K\\{mu\_glue}$;\2\6
\&{end};\2\6
\&{end};\par
\fi

\M1061. \P$\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{append\_kern};\6
\4\&{var} \37\|s: \37\\{quarterword};\C{\\{subtype} of the kern node}\2\6
\&{begin} \37$\|s\K\\{cur\_chr}$;\5
$\\{scan\_dimen}(\|s=\\{mu\_glue},\39\\{false},\39\\{false})$;\5
$\\{tail\_append}(\\{new\_kern}(\\{cur\_val}))$;\5
$\\{subtype}(\\{tail})\K\|s$;\6
\&{end};\par
\fi

\M1062. Many of the actions related to box-making are triggered by the
appearance
of braces in the input. For example, when the user says `\.{\\hbox}
\.{to} \.{100pt\{$\langle\,\hbox{hlist}\,\rangle$\}}' in vertical mode,
the information about the box size (100pt, \\{exactly}) is put onto \\{save%
\_stack}
with a level boundary word just above it, and $\\{cur\_group}\K\\{adjusted%
\_hbox\_group}$;
\TeX\ enters restricted horizontal mode to process the hlist. The right
brace eventually causes \\{save\_stack} to be restored to its former state,
at which time the information about the box size (100pt, \\{exactly}) is
available once again; a box is packaged and we leave restricted horizontal
mode, appending the new box to the current list of the enclosing mode
(in this case to the current list of vertical mode), followed by any
vertical adjustments that were removed from the box by \\{hpack}.

The next few sections of the program are therefore concerned with the
treatment of left and right curly braces.

\fi

\M1063\*. If a left brace occurs in the middle of a page or paragraph, it
simply
introduces a new level of grouping, and the matching right brace will not have
such a drastic effect. Such grouping affects neither the mode nor the
current list.

\Y\P$\4\X1056:Cases of \\{main\_control} that build boxes and lists\X%
\mathrel{+}\S$\6
\4$\\{non\_math}(\\{left\_brace})$: \37\&{begin} \37$\\{saved}(0)\K\\{line}$;\5
$\\{incr}(\\{save\_ptr})$;\5
$\\{new\_save\_level}(\\{simple\_group})$;\6
\&{end};\C{the line number is saved for possible use in warning message}\6
\4$\\{any\_mode}(\\{begin\_group})$: \37\&{begin} \37$\\{saved}(0)\K\\{line}$;\5
$\\{incr}(\\{save\_ptr})$;\5
$\\{new\_save\_level}(\\{semi\_simple\_group})$;\6
\&{end};\6
\4$\\{any\_mode}(\\{end\_group})$: \37\&{if} $\\{cur\_group}=\\{semi\_simple%
\_group}$ \1\&{then}\6
\&{begin} \37\\{unsave};\5
$\\{decr}(\\{save\_ptr})$;\C{pop unused line number from stack}\6
\&{end}\6
\4\&{else} \\{off\_save};\2\par
\fi

\M1064. We have to deal with errors in which braces and such things are not
properly nested. Sometimes the user makes an error of commission by
inserting an extra symbol, but sometimes the user makes an error of omission.
\TeX\ can't always tell one from the other, so it makes a guess and tries
to avoid getting into a loop.

The \\{off\_save} routine is called when the current group code is wrong. It
tries
to insert something into the user's input that will help clean off
the top level.

\Y\P$\4\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{off\_save};\6
\4\&{var} \37\|p: \37\\{pointer};\C{inserted token}\2\6
\&{begin} \37\&{if} $\\{cur\_group}=\\{bottom\_level}$ \1\&{then}\5
\X1066:Drop current token and complain that it was unmatched\X\6
\4\&{else} \&{begin} \37\\{back\_input};\5
$\|p\K\\{get\_avail}$;\5
$\\{link}(\\{temp\_head})\K\|p$;\5
$\\{print\_err}(\.{"Missing\ "})$;\5
\X1065:Prepare to insert a token that matches \\{cur\_group}, and print what it
is\X;\6
$\\{print}(\.{"\ inserted"})$;\5
$\\{ins\_list}(\\{link}(\\{temp\_head}))$;\5
$\\{help5}(\.{"I\'ve\ inserted\ something\ that\ you\ may\ have\ forgotten."})$%
\6
$(\.{"(See\ the\ <inserted\ text>\ above.)"})$\6
$(\.{"With\ luck,\ this\ will\ get\ me\ unwedged.\ But\ if\ you"})$\6
$(\.{"really\ didn\'t\ forget\ anything,\ try\ typing\ \`2\'\ now;\ then"})$\6
$(\.{"my\ insertion\ and\ my\ current\ dilemma\ will\ both\ disappear."})$;\5
\\{error};\6
\&{end};\2\6
\&{end};\par
\fi

\M1065. At this point, $\\{link}(\\{temp\_head})=\|p$, a pointer to an empty
one-word node.

\Y\P$\4\X1065:Prepare to insert a token that matches \\{cur\_group}, and print
what it is\X\S$\6
\&{case} $\\{cur\_group}$ \1\&{of}\6
\4\\{semi\_simple\_group}: \37\&{begin} \37$\\{info}(\|p)\K\\{cs\_token\_flag}+%
\\{frozen\_end\_group}$;\5
$\\{print\_esc}(\.{"endgroup"})$;\6
\&{end};\6
\4\\{math\_shift\_group}: \37\&{begin} \37$\\{info}(\|p)\K\\{math\_shift%
\_token}+\.{"\$"}$;\5
$\\{print\_char}(\.{"\$"})$;\6
\&{end};\6
\4\\{math\_left\_group}: \37\&{begin} \37$\\{info}(\|p)\K\\{cs\_token\_flag}+%
\\{frozen\_right}$;\5
$\\{link}(\|p)\K\\{get\_avail}$;\5
$\|p\K\\{link}(\|p)$;\5
$\\{info}(\|p)\K\\{other\_token}+\.{"."}$;\5
$\\{print\_esc}(\.{"right."})$;\6
\&{end};\6
\4\&{othercases} \37\&{begin} \37$\\{info}(\|p)\K\\{right\_brace\_token}+\.{"%
\}"}$;\5
$\\{print\_char}(\.{"\}"})$;\6
\&{end}\2\6
\&{endcases}\par
\U section~1064.\fi

\M1066. It's very hard to get this error message; indeed, the case didn't arise
until more than two years after it had been programmed.

\Y\P$\4\X1066:Drop current token and complain that it was unmatched\X\S$\6
\&{begin} \37$\\{print\_err}(\.{"Extra\ "})$;\5
$\\{print\_cmd\_chr}(\\{cur\_cmd},\39\\{cur\_chr})$;\5
$\\{help1}(\.{"Things\ are\ pretty\ mixed\ up,\ but\ I\ think\ the\ worst\ is\
over."})$;\6
\\{error};\6
\&{end}\par
\U section~1064.\fi

\M1067. The routine for a \\{right\_brace} character branches into many
subcases,
since a variety of things may happen, depending on \\{cur\_group}. Some
types of groups are not supposed to be ended by a right brace; error
messages are given in hopes of pinpointing the problem. Most branches
of this routine will be filled in later, when we are ready to understand
them; meanwhile, we must prepare ourselves to deal with such errors.

\Y\P$\4\X1056:Cases of \\{main\_control} that build boxes and lists\X%
\mathrel{+}\S$\6
\4$\\{any\_mode}(\\{right\_brace})$: \37\\{handle\_right\_brace};\par
\fi

\M1068\*. \P$\X1068\*:Declare the procedure called \\{handle\_right\_brace}\X%
\S$\6
\4\&{procedure}\1\  \37\\{handle\_right\_brace};\6
\4\&{var} \37$\|p,\39\|q$: \37\\{pointer};\C{for short-term use}\6
\|d: \37\\{scaled};\C{holds \\{split\_max\_depth} in \\{insert\_group}}\6
\|f: \37\\{integer};\C{holds \\{floating\_penalty} in \\{insert\_group}}\2\6
\&{begin} \37\&{case} $\\{cur\_group}$ \1\&{of}\6
\4\\{simple\_group}: \37\&{begin} \37\\{unsave};\5
$\\{decr}(\\{save\_ptr})$;\C{pop unused line number from stack}\6
\&{end};\6
\4\\{bottom\_level}: \37\&{begin} \37$\\{print\_err}(\.{"Too\ many\ \}\'s"})$;\5
$\\{help2}(\.{"You\'ve\ closed\ more\ groups\ than\ you\ opened."})$\6
$(\.{"Such\ booboos\ are\ generally\ harmless,\ so\ keep\ going."})$;\5
\\{error};\6
\&{end};\6
\4$\\{semi\_simple\_group},\39\\{math\_shift\_group},\39\\{math\_left\_group}$:
\37\\{extra\_right\_brace};\6
\hbox{\4}\X1085:Cases of \\{handle\_right\_brace} where a \\{right\_brace}
triggers a delayed action\X\6
\4\&{othercases} \37$\\{confusion}(\.{"rightbrace"})$\2\6
\&{endcases};\6
\&{end};\par
\U section~1030.\fi

\M1069. \P$\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{extra\_right\_brace};\2\6
\&{begin} \37$\\{print\_err}(\.{"Extra\ \},\ or\ forgotten\ "})$;\6
\&{case} $\\{cur\_group}$ \1\&{of}\6
\4\\{semi\_simple\_group}: \37$\\{print\_esc}(\.{"endgroup"})$;\6
\4\\{math\_shift\_group}: \37$\\{print\_char}(\.{"\$"})$;\6
\4\\{math\_left\_group}: \37$\\{print\_esc}(\.{"right"})$;\2\6
\&{end};\6
$\\{help5}(\.{"I\'ve\ deleted\ a\ group-closing\ symbol\ because\ it\ seems\ to%
\ be"})$\6
$(\.{"spurious,\ as\ in\ \`\$x\}\$\'.\ But\ perhaps\ the\ \}\ is\ legitimate\
and"})$\6
$(\.{"you\ forgot\ something\ else,\ as\ in\ \`\\hbox\{\$x\}\'.\ In\ such\
cases"})$\6
$(\.{"the\ way\ to\ recover\ is\ to\ insert\ both\ the\ forgotten\ and\ the"})$%
\6
$(\.{"deleted\ material,\ e.g.,\ by\ typing\ \`I\$\}\'."})$;\5
\\{error};\5
$\\{incr}(\\{align\_state})$;\6
\&{end};\par
\fi

\M1070. Here is where we clear the parameters that are supposed to revert to
their
default values after every paragraph and when internal vertical mode is
entered.

\Y\P$\4\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{normal\_paragraph};\2\6
\&{begin} \37\&{if} $\\{looseness}\I0$ \1\&{then}\5
$\\{eq\_word\_define}(\\{int\_base}+\\{looseness\_code},\390)$;\2\6
\&{if} $\\{hang\_indent}\I0$ \1\&{then}\5
$\\{eq\_word\_define}(\\{dimen\_base}+\\{hang\_indent\_code},\390)$;\2\6
\&{if} $\\{hang\_after}\I1$ \1\&{then}\5
$\\{eq\_word\_define}(\\{int\_base}+\\{hang\_after\_code},\391)$;\2\6
\&{if} $\\{par\_shape\_ptr}\I\\{null}$ \1\&{then}\5
$\\{eq\_define}(\\{par\_shape\_loc},\39\\{shape\_ref},\39\\{null})$;\2\6
\&{end};\par
\fi

\M1071. Now let's turn to the question of how \.{\\hbox} is treated. We
actually
need to consider also a slightly larger context, since constructions like
`\.{\\setbox3=}\penalty0\.{\\hbox...}' and `\.{\\lower3.8pt\\hbox...}' and
`\.{\\leaders}\penalty0\.{\\hbox...}' are supposed to invoke quite
different actions after the box has been packaged. Conversely,
constructions like `\.{\\setbox3=}' can be followed by a variety of
different kinds of boxes, and we would like to encode such things in an
efficient way.

In other words, there are two problems: To represent the context of a box,
and to represent its type.

The first problem is solved by putting a ``context code'' on the \\{save%
\_stack},
just below the two entries that give the dimensions produced by \\{scan\_spec}.
The context code is either a (signed) shift amount, or it is a large
integer $\G\\{box\_flag}$, where $\\{box\_flag}=\hbox{$2↑{30}$}$. Codes \\{box%
\_flag} through
$\\{box\_flag}+255$ represent `\.{\\setbox0}' through `\.{\\setbox255}';
codes $\\{box\_flag}+256$ through $\\{box\_flag}+511$ represent `\.{\\global%
\\setbox0}'
through `\.{\\global\\setbox255}';
code $\\{box\_flag}+512$ represents `\.{\\shipout}'; and codes $\\{box%
\_flag}+513$
through $\\{box\_flag}+515$ represent `\.{\\leaders}', `\.{\\cleaders}',
and `\.{\\xleaders}'.

The second problem is solved by giving the command code \\{make\_box} to all
control sequences that produce a box, and by using the following \\{chr\_code}
values to distinguish between them: \\{box\_code}, \\{copy\_code}, \\{last\_box%
\_code},
\\{vsplit\_code}, \\{vtop\_code}, $\\{vtop\_code}+\\{vmode}$, and $\\{vtop%
\_code}+\\{hmode}$,
where the latter two are used denote \.{\\vbox} and \.{\\hbox}, respectively.

\Y\P\D \37$\\{box\_flag}\S\O{10000000000}$\C{context code for `\.{\\setbox0}'}%
\par
\P\D \37$\\{ship\_out\_flag}\S\\{box\_flag}+512$\C{context code for `\.{%
\\shipout}'}\par
\P\D \37$\\{leader\_flag}\S\\{box\_flag}+513$\C{context code for `\.{%
\\leaders}'}\par
\P\D \37$\\{box\_code}=0$\C{\\{chr\_code} for `\.{\\box}'}\par
\P\D \37$\\{copy\_code}=1$\C{\\{chr\_code} for `\.{\\copy}'}\par
\P\D \37$\\{last\_box\_code}=2$\C{\\{chr\_code} for `\.{\\lastbox}'}\par
\P\D \37$\\{vsplit\_code}=3$\C{\\{chr\_code} for `\.{\\vsplit}'}\par
\P\D \37$\\{vtop\_code}=4$\C{\\{chr\_code} for `\.{\\vtop}'}\par
\Y\P$\4\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}\S$\6
$\\{primitive}(\.{"moveleft"},\39\\{hmove},\391)$;\5
$\\{primitive}(\.{"moveright"},\39\\{hmove},\390)$;\6
$\\{primitive}(\.{"raise"},\39\\{vmove},\391)$;\5
$\\{primitive}(\.{"lower"},\39\\{vmove},\390)$;\7
$\\{primitive}(\.{"box"},\39\\{make\_box},\39\\{box\_code})$;\5
$\\{primitive}(\.{"copy"},\39\\{make\_box},\39\\{copy\_code})$;\5
$\\{primitive}(\.{"lastbox"},\39\\{make\_box},\39\\{last\_box\_code})$;\5
$\\{primitive}(\.{"vsplit"},\39\\{make\_box},\39\\{vsplit\_code})$;\5
$\\{primitive}(\.{"vtop"},\39\\{make\_box},\39\\{vtop\_code})$;\6
$\\{primitive}(\.{"vbox"},\39\\{make\_box},\39\\{vtop\_code}+\\{vmode})$;\5
$\\{primitive}(\.{"hbox"},\39\\{make\_box},\39\\{vtop\_code}+\\{hmode})$;\6
$\\{primitive}(\.{"shipout"},\39\\{leader\_ship},\39\\{a\_leaders}-1)$;\C{$%
\\{ship\_out\_flag}=\\{leader\_flag}-1$}\6
$\\{primitive}(\.{"leaders"},\39\\{leader\_ship},\39\\{a\_leaders})$;\5
$\\{primitive}(\.{"cleaders"},\39\\{leader\_ship},\39\\{c\_leaders})$;\5
$\\{primitive}(\.{"xleaders"},\39\\{leader\_ship},\39\\{x\_leaders})$;\par
\fi

\M1072. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{hmove}: \37\&{if} $\\{chr\_code}=1$ \1\&{then}\5
$\\{print\_esc}(\.{"moveleft"})$\ \&{else} $\\{print\_esc}(\.{"moveright"})$;\2%
\6
\4\\{vmove}: \37\&{if} $\\{chr\_code}=1$ \1\&{then}\5
$\\{print\_esc}(\.{"raise"})$\ \&{else} $\\{print\_esc}(\.{"lower"})$;\2\6
\4\\{make\_box}: \37\&{case} $\\{chr\_code}$ \1\&{of}\6
\4\\{box\_code}: \37$\\{print\_esc}(\.{"box"})$;\6
\4\\{copy\_code}: \37$\\{print\_esc}(\.{"copy"})$;\6
\4\\{last\_box\_code}: \37$\\{print\_esc}(\.{"lastbox"})$;\6
\4\\{vsplit\_code}: \37$\\{print\_esc}(\.{"vsplit"})$;\6
\4\\{vtop\_code}: \37$\\{print\_esc}(\.{"vtop"})$;\6
\4$\\{vtop\_code}+\\{vmode}$: \37$\\{print\_esc}(\.{"vbox"})$;\6
\4\&{othercases} \37$\\{print\_esc}(\.{"hbox"})$\2\6
\&{endcases};\6
\4\\{leader\_ship}: \37\&{if} $\\{chr\_code}=\\{a\_leaders}$ \1\&{then}\5
$\\{print\_esc}(\.{"leaders"})$\6
\4\&{else} \&{if} $\\{chr\_code}=\\{c\_leaders}$ \1\&{then}\5
$\\{print\_esc}(\.{"cleaders"})$\6
\4\&{else} \&{if} $\\{chr\_code}=\\{x\_leaders}$ \1\&{then}\5
$\\{print\_esc}(\.{"xleaders"})$\6
\4\&{else} $\\{print\_esc}(\.{"shipout"})$;\2\2\2\par
\fi

\M1073. Constructions that require a box are started by placing a context code
on \\{save\_stack} and calling \\{scan\_box}. The \\{scan\_box} routine
verifies
that a \\{make\_box} command comes next and then it calls \\{begin\_box}.

\Y\P$\4\X1056:Cases of \\{main\_control} that build boxes and lists\X%
\mathrel{+}\S$\6
\4$\\{vmode}+\\{hmove},\39\\{hmode}+\\{vmove},\39\\{mmode}+\\{vmove}$: \37%
\&{begin} \37$\|t\K\\{cur\_chr}$;\5
\\{scan\_normal\_dimen};\6
\&{if} $\|t=0$ \1\&{then}\5
$\\{saved}(0)\K\\{cur\_val}$\ \&{else} $\\{saved}(0)\K-\\{cur\_val}$;\2\6
\\{scan\_box};\6
\&{end};\6
\4$\\{any\_mode}(\\{leader\_ship})$: \37\&{begin} \37$\\{saved}(0)\K\\{leader%
\_flag}-\\{a\_leaders}+\\{cur\_chr}$;\5
\\{scan\_box};\6
\&{end};\6
\4$\\{any\_mode}(\\{make\_box})$: \37\&{begin} \37$\\{saved}(0)\K0$;\5
\\{begin\_box};\6
\&{end};\par
\fi

\M1074. The global variable \\{cur\_box} will point to a newly-made box. If the
box
is void, we will have $\\{cur\_box}=\\{null}$. Otherwise we will have
$\\{type}(\\{cur\_box})=\\{hlist\_node}$ or \\{vlist\_node} or \\{rule\_node};
the \\{rule\_node}
case can occur only with leaders.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{cur\_box}: \37\\{pointer};\C{box to be placed into its context}\par
\fi

\M1075. The \\{box\_end} procedure does the right thing with \\{cur\_box}, if
$\\{saved}(0)$ represents the context as explained above.

\Y\P$\4\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{box\_end};\6
\4\&{var} \37\|p: \37\\{pointer};\C{\\{ord\_noad} for new box in math mode}\2\6
\&{begin} \37\&{if} $\\{saved}(0)<\\{box\_flag}$ \1\&{then}\5
\X1076:Append box \\{cur\_box} to the current list, shifted by $\\{saved}(0)$\X%
\6
\4\&{else} \&{if} $\\{saved}(0)<\\{ship\_out\_flag}$ \1\&{then}\5
\X1077:Store \(c)\\{cur\_box} in a box register\X\6
\4\&{else} \&{if} $\\{cur\_box}\I\\{null}$ \1\&{then}\6
\&{if} $\\{saved}(0)>\\{ship\_out\_flag}$ \1\&{then}\5
\X1078:Append a new leader node that uses \\{cur\_box}\X\6
\4\&{else} $\\{ship\_out}(\\{cur\_box})$;\2\2\2\2\6
\&{end};\par
\fi

\M1076. The global variable \\{adjust\_tail} will be non-null if and only if
the
current box might include adjustments that should be appended to the
current vertical list.

\Y\P$\4\X1076:Append box \\{cur\_box} to the current list, shifted by $%
\\{saved}(0)$\X\S$\6
\&{begin} \37\&{if} $\\{cur\_box}\I\\{null}$ \1\&{then}\6
\&{begin} \37$\\{shift\_amount}(\\{cur\_box})\K\\{saved}(0)$;\6
\&{if} $\\{abs}(\\{mode})=\\{vmode}$ \1\&{then}\6
\&{begin} \37$\\{append\_to\_vlist}(\\{cur\_box})$;\6
\&{if} $\\{adjust\_tail}\I\\{null}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{adjust\_head}\I\\{adjust\_tail}$ \1\&{then}\6
\&{begin} \37$\\{link}(\\{tail})\K\\{link}(\\{adjust\_head})$;\5
$\\{tail}\K\\{adjust\_tail}$;\6
\&{end};\2\6
$\\{adjust\_tail}\K\\{null}$;\6
\&{end};\2\6
\&{if} $\\{mode}>0$ \1\&{then}\5
\\{build\_page};\2\6
\&{end}\6
\4\&{else} \&{begin} \37\&{if} $\\{abs}(\\{mode})=\\{hmode}$ \1\&{then}\5
$\\{space\_factor}\K1000$\6
\4\&{else} \&{begin} \37$\|p\K\\{new\_noad}$;\5
$\\{math\_type}(\\{nucleus}(\|p))\K\\{sub\_box}$;\5
$\\{info}(\\{nucleus}(\|p))\K\\{cur\_box}$;\5
$\\{cur\_box}\K\|p$;\6
\&{end};\2\6
$\\{link}(\\{tail})\K\\{cur\_box}$;\5
$\\{tail}\K\\{cur\_box}$;\6
\&{end};\2\6
\&{end};\2\6
\&{end}\par
\U section~1075.\fi

\M1077. \P$\X1077:Store \(c)\\{cur\_box} in a box register\X\S$\6
\&{if} $\\{saved}(0)<\\{box\_flag}+256$ \1\&{then}\5
$\\{eq\_define}(\\{box\_base}-\\{box\_flag}+\\{saved}(0),\39\\{box\_ref},\39%
\\{cur\_box})$\6
\4\&{else} $\\{geq\_define}(\\{box\_base}-\\{box\_flag}-256+\\{saved}(0),\39%
\\{box\_ref},\39\\{cur\_box})$\2\par
\U section~1075.\fi

\M1078. \P$\X1078:Append a new leader node that uses \\{cur\_box}\X\S$\6
\&{begin} \37\X404:Get the next non-blank non-relax non-call token\X;\6
\&{if} $((\\{cur\_cmd}=\\{hskip})\W(\\{abs}(\\{mode})\I\\{vmode}))\V\30((\\{cur%
\_cmd}=\\{vskip})\W(\\{abs}(\\{mode})=\\{vmode}))\V\30((\\{cur\_cmd}=\\{mskip})%
\W(\\{abs}(\\{mode})=\\{mmode}))$ \1\&{then}\6
\&{begin} \37\\{append\_glue};\5
$\\{subtype}(\\{tail})\K\\{saved}(0)-(\\{leader\_flag}-\\{a\_leaders})$;\5
$\\{leader\_ptr}(\\{tail})\K\\{cur\_box}$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{print\_err}(\.{"Leaders\ not\ followed\ by\ proper\
glue"})$;\5
$\\{help3}(\.{"You\ should\ say\ \`\\leaders\ <box\ or\ rule><hskip\ or\ vskip>%
\'."})$\6
$(\.{"I\ found\ the\ <box\ or\ rule>,\ but\ there\'s\ no\ suitable"})$\6
$(\.{"<hskip\ or\ vskip>,\ so\ I\'m\ ignoring\ these\ leaders."})$;\5
\\{back\_error};\5
$\\{flush\_node\_list}(\\{cur\_box})$;\6
\&{end};\2\6
\&{end}\par
\U section~1075.\fi

\M1079. Now that we can see what eventually happens to boxes, we can consider
the first steps in their creation. The \\{begin\_box} routine is called when
$\\{saved}(0)$ is a context specification, \\{cur\_chr} specifies the type of
box desired, and $\\{cur\_cmd}=\\{make\_box}$.

\Y\P$\4\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{begin\_box};\6
\4\&{label} \37$\\{exit},\39\\{done}$;\6
\4\&{var} \37$\|p,\39\|q$: \37\\{pointer};\C{run through the current list}\6
\|m: \37\\{quarterword};\C{the length of a replacement list}\6
\|k: \37\\{halfword};\C{0 or \\{vmode} or \\{hmode}}\6
\|n: \37\\{eight\_bits};\C{a box number}\2\6
\&{begin} \37\&{case} $\\{cur\_chr}$ \1\&{of}\6
\4\\{box\_code}: \37\&{begin} \37\\{scan\_eight\_bit\_int};\5
$\\{cur\_box}\K\\{box}(\\{cur\_val})$;\5
$\\{box}(\\{cur\_val})\K\\{null}$;\C{the box becomes void, at the same level}\6
\&{end};\6
\4\\{copy\_code}: \37\&{begin} \37\\{scan\_eight\_bit\_int};\5
$\\{cur\_box}\K\\{copy\_node\_list}(\\{box}(\\{cur\_val}))$;\6
\&{end};\6
\4\\{last\_box\_code}: \37\X1080:If the current list ends with a box node,
delete it from the list and make \\{cur\_box} point to it; otherwise set $%
\\{cur\_box}\K\\{null}$\X;\6
\4\\{vsplit\_code}: \37\X1082:Split off part of a vertical box, make \\{cur%
\_box} point to it\X;\6
\4\&{othercases} \37\X1083:Initiate the construction of an hbox or vbox, then %
\&{return}\X\2\6
\&{endcases};\6
\\{box\_end};\C{in simple cases, we use the box immediately}\6
\4\\{exit}: \37\&{end};\par
\fi

\M1080. Note that the condition $\R\\{is\_char\_node}(\\{tail})$ implies that $%
\\{head}\I\\{tail}$,
since \\{head} is a one-word node.

\Y\P$\4\X1080:If the current list ends with a box node, delete it from the list
and make \\{cur\_box} point to it; otherwise set $\\{cur\_box}\K\\{null}$\X\S$\6
\&{begin} \37$\\{cur\_box}\K\\{null}$;\6
\&{if} $\\{abs}(\\{mode})=\\{mmode}$ \1\&{then}\6
\&{begin} \37\\{you\_cant};\5
$\\{help1}(\.{"Sorry;\ this\ \\lastbox\ will\ be\ void."})$;\5
\\{error};\6
\&{end}\6
\4\&{else} \&{if} $(\\{mode}=\\{vmode})\W(\\{head}=\\{tail})$ \1\&{then}\6
\&{begin} \37\\{you\_cant};\5
$\\{help2}(\.{"Sorry...I\ usually\ can\'t\ take\ things\ from\ the\ current\
page."})$\6
$(\.{"This\ \\lastbox\ will\ therefore\ be\ void."})$;\5
\\{error};\6
\&{end}\6
\4\&{else} \&{begin} \37\&{if} $\R\\{is\_char\_node}(\\{tail})$ \1\&{then}\6
\&{if} $(\\{type}(\\{tail})=\\{hlist\_node})\V(\\{type}(\\{tail})=\\{vlist%
\_node})$ \1\&{then}\5
\X1081:Remove the last box, unless it's part of a discretionary\X;\2\2\6
\&{end};\2\2\6
\&{end}\par
\U section~1079.\fi

\M1081. \P$\X1081:Remove the last box, unless it's part of a discretionary\X\S$%
\6
\&{begin} \37$\|q\K\\{head}$;\6
\1\&{repeat} \37$\|p\K\|q$;\6
\&{if} $\R\\{is\_char\_node}(\|q)$ \1\&{then}\6
\&{if} $\\{type}(\|q)=\\{disc\_node}$ \1\&{then}\6
\&{begin} \37\&{for} $\|m\K1\mathrel{\&{to}}\\{replace\_count}(\|q)$ \1\&{do}\5
$\|p\K\\{link}(\|p)$;\2\6
\&{if} $\|p=\\{tail}$ \1\&{then}\5
\&{goto} \37\\{done};\2\6
\&{end};\2\2\6
$\|q\K\\{link}(\|p)$;\6
\4\&{until}\5
$\|q=\\{tail}$;\2\6
$\\{cur\_box}\K\\{tail}$;\5
$\\{shift\_amount}(\\{cur\_box})\K0$;\5
$\\{tail}\K\|p$;\5
$\\{link}(\|p)\K\\{null}$;\6
\4\\{done}: \37\&{end}\par
\U section~1080.\fi

\M1082. Here we deal with things like `\.{\\vsplit 13 to 100pt}'.

\Y\P$\4\X1082:Split off part of a vertical box, make \\{cur\_box} point to it\X%
\S$\6
\&{begin} \37\\{scan\_eight\_bit\_int};\5
$\|n\K\\{cur\_val}$;\6
\&{if} $\R\\{scan\_keyword}(\.{"to"})$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Missing\ \`to\'\ inserted"})$;\5
$\\{help2}(\.{"I\'m\ working\ on\ \`\\vsplit<box\ number>\ to\ <dimen>\';"})$\6
$(\.{"will\ look\ for\ the\ <dimen>\ next."})$;\5
\\{error};\6
\&{end};\2\6
\\{scan\_normal\_dimen};\5
$\\{cur\_box}\K\\{vsplit}(\|n,\39\\{cur\_val})$;\6
\&{end}\par
\U section~1079.\fi

\M1083. Here is where we enter restricted horizontal mode or internal vertical
mode, in order to make a box.

\Y\P$\4\X1083:Initiate the construction of an hbox or vbox, then \&{return}\X%
\S$\6
\&{begin} \37$\|k\K\\{cur\_chr}-\\{vtop\_code}$;\5
$\\{incr}(\\{save\_ptr})$;\5
\\{scan\_spec};\6
\&{if} $\|k=\\{hmode}$ \1\&{then}\6
\&{if} $(\\{saved}(-3)<\\{box\_flag})\W(\\{abs}(\\{mode})=\\{vmode})$ \1%
\&{then}\5
$\\{new\_save\_level}(\\{adjusted\_hbox\_group})$\6
\4\&{else} $\\{new\_save\_level}(\\{hbox\_group})$\2\6
\4\&{else} \&{begin} \37\&{if} $\|k=\\{vmode}$ \1\&{then}\5
$\\{new\_save\_level}(\\{vbox\_group})$\6
\4\&{else} \&{begin} \37$\\{new\_save\_level}(\\{vtop\_group})$;\5
$\|k\K\\{vmode}$;\6
\&{end};\2\6
\\{normal\_paragraph};\6
\&{end};\2\6
\\{push\_nest};\5
$\\{mode}\K-\|k$;\6
\&{if} $\|k=\\{vmode}$ \1\&{then}\6
\&{begin} \37$\\{prev\_depth}\K\\{ignore\_depth}$;\6
\&{if} $\\{every\_vbox}\I\\{null}$ \1\&{then}\5
$\\{begin\_token\_list}(\\{every\_vbox},\39\\{every\_vbox\_text})$;\2\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{space\_factor}\K1000$;\6
\&{if} $\\{every\_hbox}\I\\{null}$ \1\&{then}\5
$\\{begin\_token\_list}(\\{every\_hbox},\39\\{every\_hbox\_text})$;\2\6
\&{end};\2\6
\&{return};\6
\&{end}\par
\U section~1079.\fi

\M1084. \P$\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{scan\_box};\C{the next input should specify a box or
perhaps a rule}\2\6
\&{begin} \37\X404:Get the next non-blank non-relax non-call token\X;\6
\&{if} $\\{cur\_cmd}=\\{make\_box}$ \1\&{then}\5
\\{begin\_box}\6
\4\&{else} \&{if} $(\\{saved}(0)\G\\{leader\_flag})\W((\\{cur\_cmd}=\\{hrule})%
\V(\\{cur\_cmd}=\\{vrule}))$ \1\&{then}\6
\&{begin} \37$\\{cur\_box}\K\\{scan\_rule\_spec}$;\5
\\{box\_end};\6
\&{end}\6
\4\&{else} \&{begin} \37\hbox{}\6
$\\{print\_err}(\.{"A\ <box>\ was\ supposed\ to\ be\ here"})$;\6
$\\{help3}(\.{"I\ was\ expecting\ to\ see\ \\hbox\ or\ \\vbox\ or\ \\copy\ or\ %
\\box\ or"})$\6
$(\.{"something\ like\ that.\ So\ you\ might\ find\ something\ missing\ in"})$\6
$(\.{"your\ output.\ But\ keep\ trying;\ you\ can\ fix\ this\ later."})$;\5
\\{back\_error};\6
\&{end};\2\2\6
\&{end};\par
\fi

\M1085. When the right brace occurs at the end of an \.{\\hbox} or \.{\\vbox}
or
\.{\\vtop} construction, the \\{package} routine comes into action. We might
also have to finish a paragraph that hasn't ended.

\Y\P$\4\X1085:Cases of \\{handle\_right\_brace} where a \\{right\_brace}
triggers a delayed action\X\S$\6
\4\\{hbox\_group}: \37$\\{package}(0)$;\6
\4\\{adjusted\_hbox\_group}: \37\&{begin} \37$\\{adjust\_tail}\K\\{adjust%
\_head}$;\5
$\\{package}(0)$;\6
\&{end};\6
\4\\{vbox\_group}: \37\&{begin} \37\\{end\_graf};\5
$\\{package}(0)$;\6
\&{end};\6
\4\\{vtop\_group}: \37\&{begin} \37\\{end\_graf};\5
$\\{package}(\\{vtop\_code})$;\6
\&{end};\par
\A sections~1100, 1118, 1132, 1133, 1168, 1173, and~1186.
\U section~1068\*.\fi

\M1086. \P$\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{package}(\|c:\\{small\_number})$;\6
\4\&{var} \37\|h: \37\\{scaled};\C{height of box}\6
\|p: \37\\{pointer};\C{first node in a box}\6
\|d: \37\\{scaled};\C{max depth}\2\6
\&{begin} \37$\|d\K\\{box\_max\_depth}$;\5
\\{unsave};\5
$\\{save\_ptr}\K\\{save\_ptr}-3$;\6
\&{if} $\\{mode}=-\\{hmode}$ \1\&{then}\5
$\\{cur\_box}\K\\{hpack}(\\{link}(\\{head}),\39\\{saved}(2),\39\\{saved}(1))$\6
\4\&{else} \&{begin} \37$\\{cur\_box}\K\\{vpackage}(\\{link}(\\{head}),\39%
\\{saved}(2),\39\\{saved}(1),\39\|d)$;\6
\&{if} $\|c=\\{vtop\_code}$ \1\&{then}\5
\X1087:Readjust the height and depth of \\{cur\_box}, for \.{\\vtop}\X;\2\6
\&{end};\2\6
\\{pop\_nest};\5
\\{box\_end};\6
\&{end};\par
\fi

\M1087. The height of a `\.{\\vtop}' box is inherited from the first item on
its list,
if that item is an \\{hlist\_node}, \\{vlist\_node}, or \\{rule\_node};
otherwise
the \.{\\vtop} height is zero.


\Y\P$\4\X1087:Readjust the height and depth of \\{cur\_box}, for \.{\\vtop}\X%
\S$\6
\&{begin} \37$\|h\K0$;\5
$\|p\K\\{list\_ptr}(\\{cur\_box})$;\6
\&{if} $\|p\I\\{null}$ \1\&{then}\6
\&{if} $\\{type}(\|p)\L\\{rule\_node}$ \1\&{then}\5
$\|h\K\\{height}(\|p)$;\2\2\6
$\\{depth}(\\{cur\_box})\K\\{depth}(\\{cur\_box})-\|h+\\{height}(\\{cur%
\_box})$;\5
$\\{height}(\\{cur\_box})\K\|h$;\6
\&{end}\par
\U section~1086.\fi

\M1088. A paragraph begins when horizontal-mode material occurs in vertical
mode,
or when the paragraph is explicitly started by `\.{\\indent}' or
`\.{\\noindent}'.

\Y\P$\4\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}\S$\6
$\\{primitive}(\.{"indent"},\39\\{start\_par},\391)$;\5
$\\{primitive}(\.{"noindent"},\39\\{start\_par},\390)$;\par
\fi

\M1089. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{start\_par}: \37\&{if} $\\{chr\_code}=0$ \1\&{then}\5
$\\{print\_esc}(\.{"noindent"})$\ \&{else} $\\{print\_esc}(\.{"indent"})$;\2\par
\fi

\M1090\*. \P$\X1056:Cases of \\{main\_control} that build boxes and lists\X%
\mathrel{+}\S$\6
\4$\\{vmode}+\\{start\_par}$: \37$\\{new\_graf}(\\{cur\_chr}>0)$;\6
\4$\\{vmode}+\\{letter},\39\\{vmode}+\\{other\_char},\39\\{vmode}+\\{char%
\_num},\39\\{vmode}+\\{xchar\_num},\39\\{vmode}+\\{char\_given},\39\\{vmode}+%
\\{math\_shift},\39\\{vmode}+\\{un\_hbox},\39\\{vmode}+\\{vrule},\39\\{vmode}+%
\\{accent},\39\\{vmode}+\\{discretionary},\39\\{vmode}+\\{hskip},\39\\{vmode}+%
\\{valign},\39\\{vmode}+\\{ex\_space}$: \37\hbox{}\6
\&{begin} \37\\{back\_input};\5
$\\{new\_graf}(\\{true})$;\6
\&{end};\par
\fi

\M1091. \P$\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{new\_graf}(\\{indented}:\\{boolean})$;\2\6
\&{begin} \37$\\{prev\_graf}\K0$;\6
\&{if} $(\\{mode}=\\{vmode})\V(\\{head}\I\\{tail})$ \1\&{then}\5
$\\{tail\_append}(\\{new\_param\_glue}(\\{par\_skip\_code}))$;\2\6
\\{push\_nest};\5
$\\{mode}\K\\{hmode}$;\5
$\\{space\_factor}\K1000$;\6
\&{if} $\\{indented}$ \1\&{then}\6
\&{begin} \37$\\{tail}\K\\{new\_null\_box}$;\5
$\\{link}(\\{head})\K\\{tail}$;\5
$\\{width}(\\{tail})\K\\{par\_indent}$;\6
\&{end};\2\6
\&{if} $\\{every\_par}\I\\{null}$ \1\&{then}\5
$\\{begin\_token\_list}(\\{every\_par},\39\\{every\_par\_text})$;\2\6
\&{if} $\\{nest\_ptr}=1$ \1\&{then}\5
\\{build\_page};\C{put \\{par\_skip} glue on current page}\2\6
\&{end};\par
\fi

\M1092. \P$\X1056:Cases of \\{main\_control} that build boxes and lists\X%
\mathrel{+}\S$\6
\4$\\{hmode}+\\{start\_par},\39\\{mmode}+\\{start\_par}$: \37\\{indent\_in%
\_hmode};\par
\fi

\M1093. \P$\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{indent\_in\_hmode};\6
\4\&{var} \37$\|p,\39\|q$: \37\\{pointer};\2\6
\&{begin} \37\&{if} $\\{cur\_chr}>0$ \1\&{then}\C{\.{\\indent}}\6
\&{begin} \37$\|p\K\\{new\_null\_box}$;\5
$\\{width}(\|p)\K\\{par\_indent}$;\6
\&{if} $\\{abs}(\\{mode})=\\{hmode}$ \1\&{then}\5
$\\{space\_factor}\K1000$\6
\4\&{else} \&{begin} \37$\|q\K\\{new\_noad}$;\5
$\\{math\_type}(\\{nucleus}(\|q))\K\\{sub\_box}$;\5
$\\{info}(\\{nucleus}(\|q))\K\|p$;\5
$\|p\K\|q$;\6
\&{end};\2\6
$\\{tail\_append}(\|p)$;\6
\&{end};\2\6
\&{end};\par
\fi

\M1094. A paragraph ends when a \\{par\_end} command is sensed, or when we are
in
horizontal mode when reaching the right brace of vertical-mode routines
like \.{\\vbox}, \.{\\insert}, or \.{\\output}.

\Y\P$\4\X1056:Cases of \\{main\_control} that build boxes and lists\X%
\mathrel{+}\S$\6
\4$\\{vmode}+\\{par\_end}$: \37\&{begin} \37\\{normal\_paragraph};\6
\&{if} $\\{mode}>0$ \1\&{then}\5
\\{build\_page};\2\6
\&{end};\6
\4$\\{hmode}+\\{par\_end}$: \37\&{begin} \37\&{if} $\\{align\_state}<0$ \1%
\&{then}\5
\\{off\_save};\C{this tries to 		recover from an alignment that didn't end
properly}\2\6
\\{end\_graf};\C{this takes us to the enclosing mode, if $\\{mode}>0$}\6
\&{if} $\\{mode}=\\{vmode}$ \1\&{then}\5
\\{build\_page};\2\6
\&{end};\6
\4$\\{hmode}+\\{stop},\39\\{hmode}+\\{vskip},\39\\{hmode}+\\{hrule},\39%
\\{hmode}+\\{un\_vbox},\39\\{hmode}+\\{halign}$: \37\\{head\_for\_vmode};\par
\fi

\M1095. \P$\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{head\_for\_vmode};\2\6
\&{begin} \37\&{if} $\\{mode}<0$ \1\&{then}\6
\&{if} $\\{cur\_cmd}\I\\{hrule}$ \1\&{then}\5
\\{off\_save}\6
\4\&{else} \&{begin} \37$\\{print\_err}(\.{"You\ can\'t\ use\ \`"})$;\5
$\\{print\_esc}(\.{"hrule"})$;\5
$\\{print}(\.{"\'\ here\ except\ with\ leaders"})$;\5
$\\{help2}(\.{"To\ put\ a\ horizontal\ rule\ in\ an\ hbox\ or\ an\
alignment,"})$\6
$(\.{"you\ should\ use\ \\leaders\ or\ \\hrulefill\ (see\ The\ TeXbook)."})$;\5
\\{error};\6
\&{end}\2\6
\4\&{else} \&{begin} \37\\{back\_input};\5
$\\{cur\_tok}\K\\{par\_token}$;\5
\\{back\_input};\5
$\\{token\_type}\K\\{inserted}$;\6
\&{end};\2\6
\&{end};\par
\fi

\M1096. \P$\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{end\_graf};\2\6
\&{begin} \37\&{if} $\\{mode}=\\{hmode}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{head}=\\{tail}$ \1\&{then}\5
\\{pop\_nest}\C{null paragraphs are ignored}\6
\4\&{else} $\\{line\_break}(\\{widow\_penalty})$;\2\6
\\{normal\_paragraph};\5
$\\{error\_count}\K0$;\6
\&{end};\2\6
\&{end};\par
\fi

\M1097. Insertion and adjustment and mark nodes are constructed by the
following
pieces of the program.

\Y\P$\4\X1056:Cases of \\{main\_control} that build boxes and lists\X%
\mathrel{+}\S$\6
\4$\\{any\_mode}(\\{insert}),\39\\{hmode}+\\{vadjust},\39\\{mmode}+%
\\{vadjust}$: \37\\{begin\_insert\_or\_adjust};\6
\4$\\{any\_mode}(\\{mark})$: \37\\{make\_mark};\par
\fi

\M1098. \P$\X1048:Forbidden cases detected in \\{main\_control}\X\mathrel{+}\S$%
\6
$\\{vmode}+\\{vadjust},\39$\par
\fi

\M1099. \P$\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{begin\_insert\_or\_adjust};\2\6
\&{begin} \37\&{if} $\\{cur\_cmd}=\\{vadjust}$ \1\&{then}\5
$\\{cur\_val}\K255$\6
\4\&{else} \&{begin} \37\\{scan\_eight\_bit\_int};\6
\&{if} $\\{cur\_val}=255$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"You\ can\'t\ "})$;\5
$\\{print\_esc}(\.{"insert"})$;\5
$\\{print\_int}(255)$;\5
$\\{help1}(\.{"I\'m\ changing\ to\ \\insert0;\ box\ 255\ is\ special."})$;\5
\\{error};\5
$\\{cur\_val}\K0$;\6
\&{end};\2\6
\&{end};\2\6
$\\{saved}(0)\K\\{cur\_val}$;\5
$\\{incr}(\\{save\_ptr})$;\5
$\\{new\_save\_level}(\\{insert\_group})$;\5
\\{scan\_left\_brace};\5
\\{normal\_paragraph};\5
\\{push\_nest};\5
$\\{mode}\K-\\{vmode}$;\5
$\\{prev\_depth}\K\\{ignore\_depth}$;\6
\&{end};\par
\fi

\M1100. \P$\X1085:Cases of \\{handle\_right\_brace} where a \\{right\_brace}
triggers a delayed action\X\mathrel{+}\S$\6
\4\\{insert\_group}: \37\&{begin} \37\\{end\_graf};\5
$\|q\K\\{split\_top\_skip}$;\5
$\\{add\_glue\_ref}(\|q)$;\5
$\|d\K\\{split\_max\_depth}$;\5
$\|f\K\\{floating\_penalty}$;\5
\\{unsave};\5
$\\{decr}(\\{save\_ptr})$;\C{now $\\{saved}(0)$ is the insertion number, or 255
for \\{vadjust}}\6
$\|p\K\\{vpack}(\\{link}(\\{head}),\39\\{natural})$;\5
\\{pop\_nest};\6
\&{if} $\\{saved}(0)<255$ \1\&{then}\6
\&{begin} \37$\\{tail\_append}(\\{get\_node}(\\{ins\_node\_size}))$;\5
$\\{type}(\\{tail})\K\\{ins\_node}$;\5
$\\{subtype}(\\{tail})\K\\{qi}(\\{saved}(0))$;\5
$\\{height}(\\{tail})\K\\{height}(\|p)+\\{depth}(\|p)$;\5
$\\{ins\_ptr}(\\{tail})\K\\{list\_ptr}(\|p)$;\5
$\\{split\_top\_ptr}(\\{tail})\K\|q$;\5
$\\{depth}(\\{tail})\K\|d$;\5
$\\{float\_cost}(\\{tail})\K\|f$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{tail\_append}(\\{get\_node}(\\{small\_node%
\_size}))$;\5
$\\{type}(\\{tail})\K\\{adjust\_node}$;\6
$\\{subtype}(\\{tail})\K0$;\C{the \\{subtype} is not used}\6
$\\{adjust\_ptr}(\\{tail})\K\\{list\_ptr}(\|p)$;\5
$\\{delete\_glue\_ref}(\|q)$;\6
\&{end};\2\6
$\\{free\_node}(\|p,\39\\{box\_node\_size})$;\6
\&{if} $\\{nest\_ptr}=0$ \1\&{then}\5
\\{build\_page};\2\6
\&{end};\6
\4\\{output\_group}: \37\X1026:Resume the page builder after an output routine
has come to an end\X;\par
\fi

\M1101. \P$\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{make\_mark};\6
\4\&{var} \37\|p: \37\\{pointer};\C{new node}\2\6
\&{begin} \37$\|p\K\\{scan\_toks}(\\{false},\39\\{true})$;\5
$\|p\K\\{get\_node}(\\{small\_node\_size})$;\5
$\\{type}(\|p)\K\\{mark\_node}$;\5
$\\{subtype}(\|p)\K0$;\C{the \\{subtype} is not used}\6
$\\{mark\_ptr}(\|p)\K\\{def\_ref}$;\5
$\\{link}(\\{tail})\K\|p$;\5
$\\{tail}\K\|p$;\6
\&{end};\par
\fi

\M1102. Penalty nodes get into a list via the \\{break\_penalty} command.

\Y\P$\4\X1056:Cases of \\{main\_control} that build boxes and lists\X%
\mathrel{+}\S$\6
\4$\\{any\_mode}(\\{break\_penalty})$: \37\\{append\_penalty};\par
\fi

\M1103. \P$\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{append\_penalty};\2\6
\&{begin} \37\\{scan\_int};\5
$\\{tail\_append}(\\{new\_penalty}(\\{cur\_val}))$;\6
\&{if} $\\{mode}=\\{vmode}$ \1\&{then}\5
\\{build\_page};\2\6
\&{end};\par
\fi

\M1104. The \\{remove\_item} command removes a penalty, kern, or glue node if
it
appears at the tail of the current list, using a brute-force linear scan.
Like \.{\\lastbox}, this command is not allowed in vertical mode (except
internal vertical mode), since the current list in vertical mode is sent
to the page builder.  But if we happen to be able to implement it in
vertical mode, we do.

\Y\P$\4\X1056:Cases of \\{main\_control} that build boxes and lists\X%
\mathrel{+}\S$\6
\4$\\{any\_mode}(\\{remove\_item})$: \37\\{delete\_last};\par
\fi

\M1105. When \\{delete\_last} is called, \\{cur\_chr} is the \\{type} of node
that
will be deleted, if present.

\Y\P$\4\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{delete\_last};\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37$\|p,\39\|q$: \37\\{pointer};\C{run through the current list}\6
\|m: \37\\{quarterword};\C{the length of a replacement list}\2\6
\&{begin} \37\&{if} $(\\{mode}=\\{vmode})\W(\\{tail}=\\{head})$ \1\&{then}\5
\X1106:Apologize for inability to do the operation now, unless \.{\\unskip}
follows non-glue\X\6
\4\&{else} \&{begin} \37\&{if} $\R\\{is\_char\_node}(\\{tail})$ \1\&{then}\6
\&{if} $\\{type}(\\{tail})=\\{cur\_chr}$ \1\&{then}\6
\&{begin} \37$\|q\K\\{head}$;\6
\1\&{repeat} \37$\|p\K\|q$;\6
\&{if} $\R\\{is\_char\_node}(\|q)$ \1\&{then}\6
\&{if} $\\{type}(\|q)=\\{disc\_node}$ \1\&{then}\6
\&{begin} \37\&{for} $\|m\K1\mathrel{\&{to}}\\{replace\_count}(\|q)$ \1\&{do}\5
$\|p\K\\{link}(\|p)$;\2\6
\&{if} $\|p=\\{tail}$ \1\&{then}\5
\&{return};\2\6
\&{end};\2\2\6
$\|q\K\\{link}(\|p)$;\6
\4\&{until}\5
$\|q=\\{tail}$;\2\6
$\\{link}(\|p)\K\\{null}$;\5
$\\{flush\_node\_list}(\\{tail})$;\5
$\\{tail}\K\|p$;\6
\&{end};\2\2\6
\&{end};\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M1106. \P$\X1106:Apologize for inability to do the operation now, unless \.{%
\\unskip} follows non-glue\X\S$\6
\&{begin} \37\&{if} $(\\{cur\_chr}\I\\{glue\_node})\V(\\{last\_glue}\I\\{max%
\_halfword})$ \1\&{then}\6
\&{begin} \37\\{you\_cant};\5
$\\{help2}(\.{"Sorry...I\ usually\ can\'t\ take\ things\ from\ the\ current\
page."})$\6
$(\.{"Try\ \`I\\vskip-\\lastskip\'\ instead."})$;\6
\&{if} $\\{cur\_chr}=\\{kern\_node}$ \1\&{then}\5
$\\{help\_line}[0]\K(\.{"Try\ \`I\\kern-\\lastkern\'\ instead."})$\6
\4\&{else} \&{if} $\\{cur\_chr}\I\\{glue\_node}$ \1\&{then}\5
$\\{help\_line}[0]\K\30(\.{"Perhaps\ you\ can\ make\ the\ output\ routine\ do\
it."})$;\2\2\6
\\{error};\6
\&{end};\2\6
\&{end}\par
\U section~1105.\fi

\M1107. \P$\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}%
\S$\6
$\\{primitive}(\.{"unpenalty"},\39\\{remove\_item},\39\\{penalty\_node})$;\6
$\\{primitive}(\.{"unkern"},\39\\{remove\_item},\39\\{kern\_node})$;\6
$\\{primitive}(\.{"unskip"},\39\\{remove\_item},\39\\{glue\_node})$;\6
$\\{primitive}(\.{"unhbox"},\39\\{un\_hbox},\39\\{box\_code})$;\6
$\\{primitive}(\.{"unhcopy"},\39\\{un\_hbox},\39\\{copy\_code})$;\6
$\\{primitive}(\.{"unvbox"},\39\\{un\_vbox},\39\\{box\_code})$;\6
$\\{primitive}(\.{"unvcopy"},\39\\{un\_vbox},\39\\{copy\_code})$;\par
\fi

\M1108. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{remove\_item}: \37\&{if} $\\{chr\_code}=\\{glue\_node}$ \1\&{then}\5
$\\{print\_esc}(\.{"unskip"})$\6
\4\&{else} \&{if} $\\{chr\_code}=\\{kern\_node}$ \1\&{then}\5
$\\{print\_esc}(\.{"unkern"})$\6
\4\&{else} $\\{print\_esc}(\.{"unpenalty"})$;\2\2\6
\4\\{un\_hbox}: \37\&{if} $\\{chr\_code}=\\{copy\_code}$ \1\&{then}\5
$\\{print\_esc}(\.{"unhcopy"})$\6
\4\&{else} $\\{print\_esc}(\.{"unhbox"})$;\2\6
\4\\{un\_vbox}: \37\&{if} $\\{chr\_code}=\\{copy\_code}$ \1\&{then}\5
$\\{print\_esc}(\.{"unvcopy"})$\6
\4\&{else} $\\{print\_esc}(\.{"unvbox"})$;\2\par
\fi

\M1109. The \\{un\_hbox} and \\{un\_vbox} commands unwrap one of the 256
current boxes.

\Y\P$\4\X1056:Cases of \\{main\_control} that build boxes and lists\X%
\mathrel{+}\S$\6
\4$\\{vmode}+\\{un\_vbox},\39\\{hmode}+\\{un\_hbox},\39\\{mmode}+\\{un\_hbox}$:
\37\\{unpackage};\par
\fi

\M1110. \P$\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{unpackage};\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37\|p: \37\\{pointer};\C{the box}\6
\|c: \37$\\{box\_code}\to\\{copy\_code}$;\C{should we copy?}\2\6
\&{begin} \37$\|c\K\\{cur\_chr}$;\5
\\{scan\_eight\_bit\_int};\5
$\|p\K\\{box}(\\{cur\_val})$;\6
\&{if} $\|p=\\{null}$ \1\&{then}\5
\&{return};\2\6
\&{if} $(\\{abs}(\\{mode})=\\{mmode})\V((\\{abs}(\\{mode})=\\{vmode})\W(%
\\{type}(\|p)\I\\{vlist\_node}))\V\30((\\{abs}(\\{mode})=\\{hmode})\W(\\{type}(%
\|p)\I\\{hlist\_node}))$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Incompatible\ list\ can\'t\ be\ unboxed"})$;\5
$\\{help3}(\.{"Sorry,\ Pandora.\ (You\ sneaky\ devil.)"})$\6
$(\.{"I\ refuse\ to\ unbox\ an\ \\hbox\ in\ vertical\ mode\ or\ vice\
versa."})$\6
$(\.{"And\ I\ can\'t\ open\ any\ boxes\ in\ math\ mode."})$;\6
\\{error};\5
\&{return};\6
\&{end};\2\6
\&{if} $\|c=\\{copy\_code}$ \1\&{then}\5
$\\{link}(\\{tail})\K\\{copy\_node\_list}(\\{list\_ptr}(\|p))$\6
\4\&{else} \&{begin} \37$\\{link}(\\{tail})\K\\{list\_ptr}(\|p)$;\5
$\\{box}(\\{cur\_val})\K\\{null}$;\5
$\\{free\_node}(\|p,\39\\{box\_node\_size})$;\6
\&{end};\2\6
\&{while} $\\{link}(\\{tail})\I\\{null}$ \1\&{do}\5
$\\{tail}\K\\{link}(\\{tail})$;\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M1111. \P$\X1048:Forbidden cases detected in \\{main\_control}\X\mathrel{+}\S$%
\6
$\\{vmode}+\\{ital\_corr},\39$\par
\fi

\M1112. Italic corrections are converted to kern nodes when the \\{ital\_corr}
command
follows a character. In math mode the same effect is achieved by appending
a kern of zero here, since italic corrections are supplied later.

\Y\P$\4\X1056:Cases of \\{main\_control} that build boxes and lists\X%
\mathrel{+}\S$\6
\4$\\{hmode}+\\{ital\_corr}$: \37\\{append\_italic\_correction};\6
\4$\\{mmode}+\\{ital\_corr}$: \37$\\{tail\_append}(\\{new\_kern}(0))$;\par
\fi

\M1113. \P$\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{append\_italic\_correction};\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37\|p: \37\\{pointer};\C{\\{char\_node} at the tail of the current
list}\6
\|f: \37\\{internal\_font\_number};\C{the font in the \\{char\_node}}\2\6
\&{begin} \37\&{if} $\\{tail}\I\\{head}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{is\_char\_node}(\\{tail})$ \1\&{then}\5
$\|p\K\\{tail}$\6
\4\&{else} \&{if} $\\{type}(\\{tail})=\\{ligature\_node}$ \1\&{then}\5
$\|p\K\\{lig\_char}(\\{tail})$\6
\4\&{else} \&{return};\2\2\6
$\|f\K\\{font}(\|p)$;\5
$\\{tail\_append}(\\{new\_kern}(\\{char\_italic}(\|f)(\\{char\_info}(\|f)(%
\\{character}(\|p)))))$;\5
$\\{subtype}(\\{tail})\K\\{explicit}$;\6
\&{end};\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M1114. Discretionary nodes are easy in the common case `\.{\\-}', but in the
general case we must process three braces full of items.

\Y\P$\4\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}\S$\6
$\\{primitive}(\.{"-"},\39\\{discretionary},\391)$;\5
$\\{primitive}(\.{"discretionary"},\39\\{discretionary},\390)$;\par
\fi

\M1115. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{discretionary}: \37\&{if} $\\{chr\_code}=1$ \1\&{then}\5
$\\{print\_esc}(\.{"-"})$\ \&{else} $\\{print\_esc}(\.{"discretionary"})$;\2\par
\fi

\M1116. \P$\X1056:Cases of \\{main\_control} that build boxes and lists\X%
\mathrel{+}\S$\6
\4$\\{hmode}+\\{discretionary},\39\\{mmode}+\\{discretionary}$: \37\\{append%
\_discretionary};\par
\fi

\M1117. The space factor does not change when we append a discretionary node,
but it starts out as 1000 in the subsidiary lists.

\Y\P$\4\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{append\_discretionary};\6
\4\&{var} \37\|c: \37\\{integer};\C{hyphen character}\2\6
\&{begin} \37$\\{tail\_append}(\\{new\_disc})$;\6
\&{if} $\\{cur\_chr}=1$ \1\&{then}\6
\&{begin} \37$\|c\K\\{hyphen\_char}[\\{cur\_font}]$;\6
\&{if} $\|c\G0$ \1\&{then}\6
\&{if} $\|c<256$ \1\&{then}\5
$\\{pre\_break}(\\{tail})\K\\{new\_character}(\\{cur\_font},\39\|c)$;\2\2\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{incr}(\\{save\_ptr})$;\5
$\\{saved}(-1)\K0$;\5
\\{scan\_left\_brace};\5
$\\{new\_save\_level}(\\{disc\_group})$;\5
\\{push\_nest};\5
$\\{mode}\K-\\{hmode}$;\5
$\\{space\_factor}\K1000$;\6
\&{end};\2\6
\&{end};\par
\fi

\M1118. The three discretionary lists are constructed somewhat as if they were
hboxes. A subroutine called \\{build\_discretionary} handles the transitions.
(This is sort of fun.)

\Y\P$\4\X1085:Cases of \\{handle\_right\_brace} where a \\{right\_brace}
triggers a delayed action\X\mathrel{+}\S$\6
\4\\{disc\_group}: \37\\{build\_discretionary};\par
\fi

\M1119. \P$\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{build\_discretionary};\6
\4\&{label} \37$\\{done},\39\\{exit}$;\6
\4\&{var} \37$\|p,\39\|q$: \37\\{pointer};\C{for link manipulation}\6
\|n: \37\\{integer};\C{length of discretionary list}\2\6
\&{begin} \37\\{unsave};\5
\X1121:Prune the current list, if necessary, until it contains only \\{char%
\_node}, \\{kern\_node}, \\{hlist\_node}, \\{vlist\_node}, \\{rule\_node}, and %
\\{ligature\_node} items; set \|n to the length of the list, and set \|q to the
list's tail\X;\6
$\|p\K\\{link}(\\{head})$;\5
\\{pop\_nest};\6
\&{case} $\\{saved}(-1)$ \1\&{of}\6
\40: \37$\\{pre\_break}(\\{tail})\K\|p$;\6
\41: \37$\\{post\_break}(\\{tail})\K\|p$;\6
\42: \37\X1120:Attach list \|p to the current list, and record its length; then
finish up and \&{return}\X;\2\6
\&{end};\C{there are no other cases}\6
$\\{incr}(\\{saved}(-1))$;\5
\\{scan\_left\_brace};\5
$\\{new\_save\_level}(\\{disc\_group})$;\5
\\{push\_nest};\5
$\\{mode}\K-\\{hmode}$;\5
$\\{space\_factor}\K1000$;\6
\4\\{exit}: \37\&{end};\par
\fi

\M1120. \P$\X1120:Attach list \|p to the current list, and record its length;
then finish up and \&{return}\X\S$\6
\&{begin} \37\&{if} $(\|n>0)\W(\\{abs}(\\{mode})=\\{mmode})$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Illegal\ math\ "})$;\5
$\\{print\_esc}(\.{"discretionary"})$;\5
$\\{help2}(\.{"Sorry:\ The\ third\ part\ of\ a\ discretionary\ break\ must\
be"})$\6
$(\.{"empty,\ in\ math\ formulas.\ I\ had\ to\ delete\ your\ third\ part."})$;\5
$\\{flush\_node\_list}(\|p)$;\5
$\|n\K0$;\5
\\{error};\6
\&{end}\6
\4\&{else} $\\{link}(\\{tail})\K\|p$;\2\6
\&{if} $\|n\L\\{max\_quarterword}$ \1\&{then}\5
$\\{replace\_count}(\\{tail})\K\|n$\6
\4\&{else} \&{begin} \37$\\{print\_err}(\.{"Discretionary\ list\ is\ too\
long"})$;\5
$\\{help2}(\.{"Wow---I\ never\ thought\ anybody\ would\ tweak\ me\ here."})$\6
$(\.{"You\ can\'t\ seriously\ need\ such\ a\ huge\ discretionary\ list?"})$;\5
\\{error};\6
\&{end};\2\6
\&{if} $\|n>0$ \1\&{then}\5
$\\{tail}\K\|q$;\2\6
$\\{decr}(\\{save\_ptr})$;\5
\&{return};\6
\&{end}\par
\U section~1119.\fi

\M1121. During this loop, $\|p=\\{link}(\|q)$ and there are \|n items preceding
\|p.

\Y\P$\4\X1121:Prune the current list, if necessary, until it contains only %
\\{char\_node}, \\{kern\_node}, \\{hlist\_node}, \\{vlist\_node}, \\{rule%
\_node}, and \\{ligature\_node} items; set \|n to the length of the list, and
set \|q to the list's tail\X\S$\6
$\|q\K\\{head}$;\5
$\|p\K\\{link}(\|q)$;\5
$\|n\K0$;\6
\&{while} $\|p\I\\{null}$ \1\&{do}\6
\&{begin} \37\&{if} $\R\\{is\_char\_node}(\|p)$ \1\&{then}\6
\&{if} $\\{type}(\|p)>\\{rule\_node}$ \1\&{then}\6
\&{if} $\\{type}(\|p)\I\\{kern\_node}$ \1\&{then}\6
\&{if} $\\{type}(\|p)\I\\{ligature\_node}$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Improper\ discretionary\ list"})$;\5
$\\{help1}(\.{"Discretionary\ lists\ must\ contain\ only\ boxes\ and\
kerns."})$;\6
\\{error};\5
\\{begin\_diagnostic};\5
$\\{print\_nl}(\.{"The\ following\ discretionary\ sublist\ has\ been\
deleted:"})$;\5
$\\{show\_box}(\|p)$;\5
$\\{end\_diagnostic}(\\{true})$;\5
$\\{flush\_node\_list}(\|p)$;\5
$\\{link}(\|q)\K\\{null}$;\5
\&{goto} \37\\{done};\6
\&{end};\2\2\2\2\6
$\|q\K\|p$;\5
$\|p\K\\{link}(\|q)$;\5
$\\{incr}(\|n)$;\6
\&{end};\2\6
\4\\{done}: \37\par
\U section~1119.\fi

\M1122\*. We need only two more things to complete the horizontal mode
routines, namely
the \.{\\xchar} and \.{\\accent} primitives.

\Y\P$\4\X1056:Cases of \\{main\_control} that build boxes and lists\X%
\mathrel{+}\S$\6
\4$\\{hmode}+\\{xchar\_num}$: \37\&{begin} \37\\{scan\_xchar\_num};\5
$\\{link}(\\{tail})\K\\{new\_xchar}(\\{cur\_font},\39\\{cur\_val})$;\6
\&{if} $\\{link}(\\{tail})\I\\{null}$ \1\&{then}\5
$\\{tail}\K\\{link}(\\{link}(\\{tail}))$;\2\6
$\\{space\_factor}\K1000$;\6
\&{end};\6
\4$\\{hmode}+\\{accent}$: \37\\{make\_accent};\par
\fi

\M1123. The positioning of accents is straightforward but tedious. Given an
accent
of width \|a, designed for characters of height \|x and slant \|s;
and given a character of width \|w, height \|h, and slant \|t: We will shift
the accent down by $\|x-\|h$, and we will insert kern nodes that have the
effect of
centering the accent over the character and shifting the accent to the
right by $\delta={1\over2}(w-a)+h\cdot t-x\cdot s$.  If either character is
absent from the font, we will simply use the other, without shifting.

\Y\P$\4\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{make\_accent};\6
\4\&{var} \37$\|s,\39\|t$: \37\\{real};\C{amount of slant}\6
$\|p,\39\|q,\39\|r$: \37\\{pointer};\C{character, box, and kern nodes}\6
\|f: \37\\{internal\_font\_number};\C{relevant font}\6
$\|a,\39\|h,\39\|x,\39\|w,\39\\{delta}$: \37\\{scaled};\C{heights and widths,
as explained above}\6
\|i: \37\\{four\_quarters};\C{character information}\2\6
\&{begin} \37\\{scan\_char\_num};\5
$\|f\K\\{cur\_font}$;\5
$\|p\K\\{new\_character}(\|f,\39\\{cur\_val})$;\6
\&{if} $\|p\I\\{null}$ \1\&{then}\6
\&{begin} \37$\|x\K\\{x\_height}(\|f)$;\5
$\|s\K\\{slant}(\|f)/\\{float\_constant}(65536)$;\5
$\|a\K\\{char\_width}(\|f)(\\{char\_info}(\|f)(\\{character}(\|p)))$;\6
\\{do\_assignments};\6
\X1124\*:Create a character node \|q for the next character, but set $\|q\K%
\\{null}$ if problems arise\X;\6
\&{if} $\|q\I\\{null}$ \1\&{then}\5
\X1125\*:Append the accent with appropriate kerns, then set $\|p\K\|q$\X;\2\6
$\\{link}(\\{tail})\K\|p$;\5
$\\{tail}\K\|p$;\5
$\\{space\_factor}\K1000$;\6
\&{end};\2\6
\&{end};\par
\fi

\M1124\*. \P$\X1124\*:Create a character node \|q for the next character, but
set $\|q\K\\{null}$ if problems arise\X\S$\6
$\|q\K\\{null}$;\5
$\|f\K\\{cur\_font}$;\6
\&{if} $(\\{cur\_cmd}=\\{letter})\V(\\{cur\_cmd}=\\{other\_char})\V(\\{cur%
\_cmd}=\\{char\_given})$ \1\&{then}\5
$\|q\K\\{new\_character}(\|f,\39\\{cur\_chr})$\6
\4\&{else} \&{if} $\\{cur\_cmd}=\\{char\_num}$ \1\&{then}\6
\&{begin} \37\\{scan\_char\_num};\5
$\|q\K\\{new\_character}(\|f,\39\\{cur\_val})$;\6
\&{end}\6
\4\&{else} \&{if} $\\{cur\_cmd}=\\{xchar\_num}$ \1\&{then}\6
\&{begin} \37\\{scan\_xchar\_num};\5
$\|q\K\\{new\_xchar}(\|f,\39\\{cur\_val})$;\6
\&{end}\6
\4\&{else} \\{back\_input}\2\2\2\par
\U section~1123.\fi

\M1125\*. The kern nodes appended here must be distinguished from other kerns,
lest
they be wiped away by the hyphenation algorithm or by a previous line break.

The two kerns are computed with (machine-dependent) \\{real} arithmetic, but
their sum is machine-independent; the net effect is machine-independent,
because the user cannot remove these nodes nor access them via \.{\\lastkern}.

\Y\P$\4\X1125\*:Append the accent with appropriate kerns, then set $\|p\K\|q$\X%
\S$\6
\&{begin} \37$\|t\K\\{slant}(\|f)/\\{float\_constant}(65536)$;\6
\&{if} $\\{is\_xchar\_node}(\|q)$ \1\&{then}\5
$\|i\K\\{char\_info}(\|f)(\\{character}(\\{link}(\|q)))$\6
\4\&{else} $\|i\K\\{char\_info}(\|f)(\\{character}(\|q))$;\2\6
$\|w\K\\{char\_width}(\|f)(\|i)$;\5
$\|h\K\\{char\_height}(\|f)(\\{height\_depth}(\|i))$;\6
\&{if} $\|h\I\|x$ \1\&{then}\C{the accent must be shifted up or down}\6
\&{begin} \37$\|p\K\\{hpack}(\|p,\39\\{natural})$;\5
$\\{shift\_amount}(\|p)\K\|x-\|h$;\6
\&{end};\2\6
$\\{delta}\K\\{round}((\|w-\|a)/\\{float\_constant}(2)+\|h\ast\|t-\|x\ast\|s)$;%
\5
$\|r\K\\{new\_kern}(\\{delta})$;\5
$\\{subtype}(\|r)\K\\{acc\_kern}$;\5
$\\{link}(\\{tail})\K\|r$;\5
$\\{link}(\|r)\K\|p$;\5
$\\{tail}\K\\{new\_kern}(-\|a-\\{delta})$;\5
$\\{subtype}(\\{tail})\K\\{acc\_kern}$;\5
$\\{link}(\|p)\K\\{tail}$;\6
\&{if} $\\{is\_xchar\_node}(\|q)$ \1\&{then}\C{in this case we want to bypass
the xchar part}\6
\&{begin} \37$\\{tail\_append}(\|q)$;\5
$\|p\K\\{link}(\|q)$;\6
\&{end}\6
\4\&{else} $\|p\K\|q$;\2\6
\&{end}\par
\U section~1123.\fi

\M1126. When `\.{\\cr}' or `\.{\\span}' or a tab mark comes through the scanner
into \\{main\_control}, it might be that the user has foolishly inserted
one of them into something that has nothing to do with alignment. But it is
far more likely that a left brace or right brace has been omitted, since
\\{get\_next} takes actions appropriate to alignment only when `\.{\\cr}'
or `\.{\\span}' or tab marks occur with $\\{align\_state}=0$. The following
program attempts to make an appropriate recovery.

\Y\P$\4\X1056:Cases of \\{main\_control} that build boxes and lists\X%
\mathrel{+}\S$\6
\4$\\{any\_mode}(\\{car\_ret}),\39\\{any\_mode}(\\{tab\_mark})$: \37\\{align%
\_error};\6
\4$\\{any\_mode}(\\{no\_align})$: \37\\{no\_align\_error};\6
\4$\\{any\_mode}(\\{omit})$: \37\\{omit\_error};\par
\fi

\M1127. \P$\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{align\_error};\2\6
\&{begin} \37\&{if} $\\{abs}(\\{align\_state})>2$ \1\&{then}\5
\X1128:Express consternation over the fact that no alignment is in progress\X\6
\4\&{else} \&{begin} \37\\{back\_input};\6
\&{if} $\\{align\_state}<0$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Missing\ \{\ inserted"})$;\5
$\\{incr}(\\{align\_state})$;\5
$\\{cur\_tok}\K\\{left\_brace\_token}+\.{"\{"}$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{print\_err}(\.{"Missing\ \}\ inserted"})$;\5
$\\{decr}(\\{align\_state})$;\5
$\\{cur\_tok}\K\\{right\_brace\_token}+\.{"\}"}$;\6
\&{end};\2\6
$\\{help3}(\.{"I\'ve\ put\ in\ what\ seems\ to\ be\ necessary\ to\ fix"})$\6
$(\.{"the\ current\ column\ of\ the\ current\ alignment."})$\6
$(\.{"Try\ to\ go\ on,\ since\ this\ might\ almost\ work."})$;\5
\\{ins\_error};\6
\&{end};\2\6
\&{end};\par
\fi

\M1128. \P$\X1128:Express consternation over the fact that no alignment is in
progress\X\S$\6
\&{begin} \37$\\{print\_err}(\.{"Misplaced\ "})$;\5
$\\{print\_cmd\_chr}(\\{cur\_cmd},\39\\{cur\_chr})$;\6
\&{if} $\\{cur\_tok}=\\{tab\_token}+\.{"\&"}$ \1\&{then}\6
\&{begin} \37$\\{help6}(\.{"I\ can\'t\ figure\ out\ why\ you\ would\ want\ to\
use\ a\ tab\ mark"})$\6
$(\.{"here.\ If\ you\ just\ want\ an\ ampersand,\ the\ remedy\ is"})$\6
$(\.{"simple:\ Just\ type\ \`I\\\&\'\ now.\ But\ if\ some\ right\ brace"})$\6
$(\.{"up\ above\ has\ ended\ a\ previous\ alignment\ prematurely,"})$\6
$(\.{"you\'re\ probably\ due\ for\ more\ error\ messages,\ and\ you"})$\6
$(\.{"might\ try\ typing\ \`S\'\ now\ just\ to\ see\ what\ is\
salvageable."})$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{help5}(\.{"I\ can\'t\ figure\ out\ why\ you\ would\
want\ to\ use\ a\ tab\ mark"})$\6
$(\.{"or\ \\cr\ or\ \\span\ just\ now.\ If\ something\ like\ a\ right\
brace"})$\6
$(\.{"up\ above\ has\ ended\ a\ previous\ alignment\ prematurely,"})$\6
$(\.{"you\'re\ probably\ due\ for\ more\ error\ messages,\ and\ you"})$\6
$(\.{"might\ try\ typing\ \`S\'\ now\ just\ to\ see\ what\ is\
salvageable."})$;\6
\&{end};\2\6
\\{error};\6
\&{end}\par
\U section~1127.\fi

\M1129. The help messages here contain a little white lie, since \.{\\noalign}
and \.{\\omit} are allowed also after `\.{\\noalign\{...\}}'.

\Y\P$\4\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{no\_align\_error};\2\6
\&{begin} \37$\\{print\_err}(\.{"Misplaced\ "})$;\5
$\\{print\_esc}(\.{"noalign"})$;\5
$\\{help2}(\.{"I\ expect\ to\ see\ \\noalign\ only\ after\ the\ \\cr\ of"})$\6
$(\.{"an\ alignment.\ Proceed,\ and\ I\'ll\ ignore\ this\ case."})$;\5
\\{error};\6
\&{end};\6
\4\&{procedure}\1\  \37\\{omit\_error};\2\6
\&{begin} \37$\\{print\_err}(\.{"Misplaced\ "})$;\5
$\\{print\_esc}(\.{"omit"})$;\5
$\\{help2}(\.{"I\ expect\ to\ see\ \\omit\ only\ after\ tab\ marks\ or\ the\ %
\\cr\ of"})$\6
$(\.{"an\ alignment.\ Proceed,\ and\ I\'ll\ ignore\ this\ case."})$;\5
\\{error};\6
\&{end};\par
\fi

\M1130. We've now covered most of the abuses of \.{\\halign} and \.{\\valign}.
Let's take a look at what happens when they are used correctly.

\Y\P$\4\X1056:Cases of \\{main\_control} that build boxes and lists\X%
\mathrel{+}\S$\6
\4$\\{vmode}+\\{halign},\39\\{hmode}+\\{valign}$: \37\\{init\_align};\6
\4$\\{mmode}+\\{halign}$: \37\&{if} $\\{privileged}$ \1\&{then}\5
\\{init\_align};\2\6
\4$\\{vmode}+\\{endv},\39\\{hmode}+\\{endv}$: \37\\{do\_endv};\par
\fi

\M1131. An \\{align\_group} code is supposed to remain on the \\{save\_stack}
during an entire alignment, until \\{fin\_align} removes it.

\Y\P$\4\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{do\_endv};\2\6
\&{begin} \37\&{if} $\\{cur\_group}=\\{align\_group}$ \1\&{then}\6
\&{begin} \37\\{end\_graf};\6
\&{if} $\\{fin\_col}$ \1\&{then}\5
\\{fin\_row};\2\6
\&{end}\6
\4\&{else} \\{off\_save};\2\6
\&{end};\par
\fi

\M1132. \P$\X1085:Cases of \\{handle\_right\_brace} where a \\{right\_brace}
triggers a delayed action\X\mathrel{+}\S$\6
\4\\{align\_group}: \37\&{begin} \37\\{back\_input};\5
$\\{cur\_tok}\K\\{cs\_token\_flag}+\\{frozen\_cr}$;\5
$\\{print\_err}(\.{"Missing\ "})$;\5
$\\{print\_esc}(\.{"cr"})$;\5
$\\{print}(\.{"\ inserted"})$;\5
$\\{help1}(\.{"I\'m\ guessing\ that\ you\ meant\ to\ end\ an\ alignment\
here."})$;\5
\\{ins\_error};\6
\&{end};\par
\fi

\M1133. \P$\X1085:Cases of \\{handle\_right\_brace} where a \\{right\_brace}
triggers a delayed action\X\mathrel{+}\S$\6
\4\\{no\_align\_group}: \37\&{begin} \37\\{end\_graf};\5
\\{unsave};\5
\\{align\_peek};\6
\&{end};\par
\fi

\M1134. Finally, \.{\\endcsname} is not supposed to get through to \\{main%
\_control}.

\Y\P$\4\X1056:Cases of \\{main\_control} that build boxes and lists\X%
\mathrel{+}\S$\6
\4$\\{any\_mode}(\\{end\_cs\_name})$: \37\\{cs\_error};\par
\fi

\M1135. \P$\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{cs\_error};\2\6
\&{begin} \37$\\{print\_err}(\.{"Extra\ "})$;\5
$\\{print\_esc}(\.{"endcsname"})$;\5
$\\{help1}(\.{"I\'m\ ignoring\ this,\ since\ I\ wasn\'t\ doing\ a\ %
\\csname."})$;\5
\\{error};\6
\&{end};\par
\fi

\N1136.  \[48] Building math lists.
The routines that \TeX\ uses to create mlists are similar to those we have
just seen for the generation of hlists and vlists. But it is necessary to
make ``noads'' as well as nodes, so the reader should review the
discussion of math mode data structures before trying to make sense out of
the following program.

Here is a little routine that needs to be done whenever a subformula
is about to be processed. The parameter is a code like \\{math\_group}.

\Y\P$\4\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{push\_math}(\|c:\\{group\_code})$;\2\6
\&{begin} \37\\{push\_nest};\5
$\\{mode}\K-\\{mmode}$;\5
$\\{incompleat\_noad}\K\\{null}$;\5
$\\{new\_save\_level}(\|c)$;\6
\&{end};\par
\fi

\M1137. We get into math mode from horizontal mode when a `\.\$' (i.e., a
\\{math\_shift} character) is scanned. We must check to see whether this
`\.\$' is immediately followed by another, in case display math mode is
called for.

\Y\P$\4\X1056:Cases of \\{main\_control} that build boxes and lists\X%
\mathrel{+}\S$\6
\4$\\{hmode}+\\{math\_shift}$: \37\\{init\_math};\par
\fi

\M1138. \P$\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{init\_math};\6
\4\&{label} \37$\\{reswitch},\39\\{found},\39\\{not\_found},\39\\{done}$;\6
\4\&{var} \37\|w: \37\\{scaled};\C{new or partial \\{pre\_display\_size}}\6
\|l: \37\\{scaled};\C{new \\{display\_width}}\6
\|s: \37\\{scaled};\C{new \\{display\_indent}}\6
\|p: \37\\{pointer};\C{current node when calculating \\{pre\_display\_size}}\6
\|q: \37\\{pointer};\C{glue specification when calculating \\{pre\_display%
\_size}}\6
\|f: \37\\{internal\_font\_number};\C{font in current \\{char\_node}}\6
\|n: \37\\{integer};\C{scope of paragraph shape specification}\6
\|v: \37\\{scaled};\C{\|w plus possible glue amount}\6
\|d: \37\\{scaled};\C{increment to \|v}\2\6
\&{begin} \37\\{get\_token};\C{\\{get\_x\_token} would fail on \.{\\ifmmode}!}\6
\&{if} $(\\{cur\_cmd}=\\{math\_shift})\W(\\{mode}>0)$ \1\&{then}\5
\X1145:Go into display math mode\X\6
\4\&{else} \&{begin} \37\\{back\_input};\5
\X1139:Go into ordinary math mode\X;\6
\&{end};\2\6
\&{end};\par
\fi

\M1139. \P$\X1139:Go into ordinary math mode\X\S$\6
\&{begin} \37$\\{push\_math}(\\{math\_shift\_group})$;\5
$\\{eq\_word\_define}(\\{int\_base}+\\{cur\_fam\_code},\39-1)$;\6
\&{if} $\\{every\_math}\I\\{null}$ \1\&{then}\5
$\\{begin\_token\_list}(\\{every\_math},\39\\{every\_math\_text})$;\2\6
\&{end}\par
\U sections~1138 and~1142.\fi

\M1140. We get into ordinary math mode from display math mode when `\.{\\eqno}'
or
`\.{\\leqno}' appears. In such cases \\{cur\_chr} will be 0 or~1, respectively;
the value of \\{cur\_chr} is placed onto \\{save\_stack} for safe keeping.

\Y\P$\4\X1056:Cases of \\{main\_control} that build boxes and lists\X%
\mathrel{+}\S$\6
\4$\\{mmode}+\\{eq\_no}$: \37\&{if} $\\{privileged}$ \1\&{then}\5
\\{start\_eq\_no};\2\par
\fi

\M1141. \P$\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}%
\S$\6
$\\{primitive}(\.{"eqno"},\39\\{eq\_no},\390)$;\5
$\\{primitive}(\.{"leqno"},\39\\{eq\_no},\391)$;\par
\fi

\M1142. When \TeX\ is in display math mode, $\\{cur\_group}=\\{math\_shift%
\_group}$,
so it is not necessary for the \\{start\_eq\_no} procedure to test for
this condition.

\Y\P$\4\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{start\_eq\_no};\2\6
\&{begin} \37$\\{saved}(0)\K\\{cur\_chr}$;\5
$\\{incr}(\\{save\_ptr})$;\5
\X1139:Go into ordinary math mode\X;\6
\&{end};\par
\fi

\M1143. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{eq\_no}: \37\&{if} $\\{chr\_code}=1$ \1\&{then}\5
$\\{print\_esc}(\.{"leqno"})$\ \&{else} $\\{print\_esc}(\.{"eqno"})$;\2\par
\fi

\M1144. \P$\X1048:Forbidden cases detected in \\{main\_control}\X\mathrel{+}\S$%
\6
$\\{non\_math}(\\{eq\_no}),\39$\par
\fi

\M1145. When we enter display math mode, we need to call \\{line\_break} to
process the partial paragraph that has just been interrupted by the
display. Then we can set the proper values of \\{display\_width} and
\\{display\_indent} and \\{pre\_display\_size}.

\Y\P$\4\X1145:Go into display math mode\X\S$\6
\&{begin} \37\&{if} $\\{head}=\\{tail}$ \1\&{then}\C{`\.{\\noindent\$\$}' or `%
\.{\$\${ }\$\$}'}\6
\&{begin} \37\\{pop\_nest};\5
$\|w\K-\\{max\_dimen}$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{line\_break}(\\{display\_widow\_penalty})$;\6
\X1146:Calculate the natural width, \|w, by which the characters of the final
line extend to the right of the reference point, plus two ems; or set $\|w\K%
\\{max\_dimen}$ if the non-blank information on that line is affected by
stretching or shrinking\X;\6
\&{end};\C{Now we are in vertical mode, working on the list that will contain
the display}\2\6
\X1149:Calculate the length, \|l, and the shift amount, \|s, of the display
lines\X;\6
$\\{push\_math}(\\{math\_shift\_group})$;\5
$\\{mode}\K\\{mmode}$;\5
$\\{eq\_word\_define}(\\{int\_base}+\\{cur\_fam\_code},\39-1)$;\6
$\\{eq\_word\_define}(\\{dimen\_base}+\\{pre\_display\_size\_code},\39\|w)$;\5
$\\{eq\_word\_define}(\\{dimen\_base}+\\{display\_width\_code},\39\|l)$;\5
$\\{eq\_word\_define}(\\{dimen\_base}+\\{display\_indent\_code},\39\|s)$;\6
\&{if} $\\{every\_display}\I\\{null}$ \1\&{then}\5
$\\{begin\_token\_list}(\\{every\_display},\39\\{every\_display\_text})$;\2\6
\&{if} $\\{nest\_ptr}=1$ \1\&{then}\5
\\{build\_page};\2\6
\&{end}\par
\U section~1138.\fi

\M1146. \P$\X1146:Calculate the natural width, \|w, by which the characters of
the final line extend to the right of the reference point, plus two ems; or set
$\|w\K\\{max\_dimen}$ if the non-blank information on that line is affected by
stretching or shrinking\X\S$\6
$\|v\K\\{shift\_amount}(\\{just\_box})+2\ast\\{quad}(\\{cur\_font})$;\5
$\|w\K-\\{max\_dimen}$;\5
$\|p\K\\{list\_ptr}(\\{just\_box})$;\6
\&{while} $\|p\I\\{null}$ \1\&{do}\6
\&{begin} \37\X1147\*:Let \|d be the natural width of node \|p; if the node is
``visible,'' \&{goto} \\{found}; if the node is glue that stretches or shrinks,
set $\|v\K\\{max\_dimen}$\X;\6
\&{if} $\|v<\\{max\_dimen}$ \1\&{then}\5
$\|v\K\|v+\|d$;\2\6
\&{goto} \37\\{not\_found};\6
\4\\{found}: \37\&{if} $\|v<\\{max\_dimen}$ \1\&{then}\6
\&{begin} \37$\|v\K\|v+\|d$;\5
$\|w\K\|v$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\|w\K\\{max\_dimen}$;\5
\&{goto} \37\\{done};\6
\&{end};\2\6
\4\\{not\_found}: \37$\|p\K\\{link}(\|p)$;\6
\&{end};\2\6
\4\\{done}: \37\par
\U section~1145.\fi

\M1147\*. \P$\X1147\*:Let \|d be the natural width of node \|p; if the node is
``visible,'' \&{goto} \\{found}; if the node is glue that stretches or shrinks,
set $\|v\K\\{max\_dimen}$\X\S$\6
\4\\{reswitch}: \37\&{if} $\\{is\_char\_node}(\|p)$ \1\&{then}\6
\&{begin} \37$\\{bypass\_xchar}(\|p)$;\5
$\|f\K\\{font}(\|p)$;\5
$\|d\K\\{char\_width}(\|f)(\\{char\_info}(\|f)(\\{character}(\|p)))$;\5
\&{goto} \37\\{found};\6
\&{end};\2\6
\&{case} $\\{type}(\|p)$ \1\&{of}\6
\4$\\{hlist\_node},\39\\{vlist\_node},\39\\{rule\_node}$: \37\&{begin} \37$\|d%
\K\\{width}(\|p)$;\5
\&{goto} \37\\{found};\6
\&{end};\6
\4\\{ligature\_node}: \37\X652:Make node \|p look like a \\{char\_node} and %
\&{goto} \\{reswitch}\X;\6
\4$\\{kern\_node},\39\\{math\_node}$: \37$\|d\K\\{width}(\|p)$;\6
\4\\{glue\_node}: \37\X1148:Let \|d be the natural width of this glue; if
stretching or shrinking, set $\|v\K\\{max\_dimen}$; \&{goto} \\{found} in the
case of leaders\X;\6
\4\\{whatsit\_node}: \37\X1361:Let \|d be the width of the whatsit \|p\X;\6
\4\&{othercases} \37$\|d\K0$\2\6
\&{endcases}\par
\U section~1146.\fi

\M1148. We need to be careful that \|w, \|v, and \|d do not depend on any %
\\{glue\_set}
values, since such values are subject to system-dependent rounding.
System-dependent numbers are not allowed to infiltrate parameters like
\\{pre\_display\_size}, since \TeX82 is supposed to make the same decisions on
all
machines.

\Y\P$\4\X1148:Let \|d be the natural width of this glue; if stretching or
shrinking, set $\|v\K\\{max\_dimen}$; \&{goto} \\{found} in the case of leaders%
\X\S$\6
\&{begin} \37$\|q\K\\{glue\_ptr}(\|p)$;\5
$\|d\K\\{width}(\|q)$;\6
\&{if} $\\{glue\_sign}(\\{just\_box})=\\{stretching}$ \1\&{then}\6
\&{begin} \37\&{if} $(\\{glue\_order}(\\{just\_box})=\\{stretch\_order}(\|q))\W%
\30(\\{stretch}(\|q)\I0)$ \1\&{then}\5
$\|v\K\\{max\_dimen}$;\2\6
\&{end}\6
\4\&{else} \&{if} $\\{glue\_sign}(\\{just\_box})=\\{shrinking}$ \1\&{then}\6
\&{begin} \37\&{if} $(\\{glue\_order}(\\{just\_box})=\\{shrink\_order}(\|q))\W%
\30(\\{shrink}(\|q)\I0)$ \1\&{then}\5
$\|v\K\\{max\_dimen}$;\2\6
\&{end};\2\2\6
\&{if} $\\{subtype}(\|p)\G\\{a\_leaders}$ \1\&{then}\5
\&{goto} \37\\{found};\2\6
\&{end}\par
\U section~1147\*.\fi

\M1149. A displayed equation is considered to be three lines long, so we
calculate the length and offset of line number $\\{prev\_graf}+2$.

\Y\P$\4\X1149:Calculate the length, \|l, and the shift amount, \|s, of the
display lines\X\S$\6
\&{if} $\\{par\_shape\_ptr}=\\{null}$ \1\&{then}\6
\&{if} $(\\{hang\_indent}\I0)\W\30(((\\{hang\_after}\G0)\W(\\{prev\_graf}+2>%
\\{hang\_after}))\V\30(\\{prev\_graf}+1<-\\{hang\_after}))$ \1\&{then}\6
\&{begin} \37$\|l\K\\{hsize}-\\{abs}(\\{hang\_indent})$;\6
\&{if} $\\{hang\_indent}>0$ \1\&{then}\5
$\|s\K\\{hang\_indent}$\ \&{else} $\|s\K0$;\2\6
\&{end}\6
\4\&{else} \&{begin} \37$\|l\K\\{hsize}$;\5
$\|s\K0$;\6
\&{end}\2\6
\4\&{else} \&{begin} \37$\|n\K\\{info}(\\{par\_shape\_ptr})$;\6
\&{if} $\\{prev\_graf}+2\G\|n$ \1\&{then}\5
$\|p\K\\{par\_shape\_ptr}+2\ast\|n$\6
\4\&{else} $\|p\K\\{par\_shape\_ptr}+2\ast(\\{prev\_graf}+2)$;\2\6
$\|s\K\\{mem}[\|p-1].\\{sc}$;\5
$\|l\K\\{mem}[\|p].\\{sc}$;\6
\&{end}\2\par
\U section~1145.\fi

\M1150. Subformulas of math formulas cause a new level of math mode to be
entered,
on the semantic nest as well as the save stack. These subformulas arise in
several ways: (1)~A left brace by itself indicates the beginning of a
subformula that will be put into a box, thereby freezing its glue and
preventing line breaks. (2)~A subscript or superscript is treated as a
subformula if it is not a single character; the same applies to
the nucleus of things like \.{\\underline}. (3)~The \.{\\left} primitive
initiates a subformula that will be terminated by a matching \.{\\right}.
The group codes placed on \\{save\_stack} in these three cases are
\\{math\_group}, \\{math\_group}, and \\{math\_left\_group}, respectively.

Here is the code that handles case (1); the other cases are not quite as
trivial, so we shall consider them later.

\Y\P$\4\X1056:Cases of \\{main\_control} that build boxes and lists\X%
\mathrel{+}\S$\6
\4$\\{mmode}+\\{left\_brace}$: \37\&{begin} \37$\\{tail\_append}(\\{new%
\_noad})$;\5
\\{back\_input};\5
$\\{scan\_math}(\\{nucleus}(\\{tail}))$;\6
\&{end};\par
\fi

\M1151. Recall that the \\{nucleus}, \\{subscr}, and \\{supscr} fields in a
noad are
broken down into subfields called \\{math\_type} and either \\{info} or
$(\\{fam},\\{character})$. The job of \\{scan\_math} is to figure out what to
place
in one of these principal fields; it looks at the subformula that
comes next in the input, and places an encoding of that subformula
into a given word of \\{mem}.

\Y\P\D \37$\\{fam\_in\_range}\S((\\{cur\_fam}\G0)\W(\\{cur\_fam}<16))$\par
\Y\P$\4\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{scan\_math}(\|p:\\{pointer})$;\6
\4\&{label} \37$\\{restart},\39\\{reswitch},\39\\{exit}$;\6
\4\&{var} \37\|c: \37\\{integer};\C{math character code}\2\6
\&{begin} \37\\{restart}: \37\X404:Get the next non-blank non-relax non-call
token\X;\6
\4\\{reswitch}: \37\&{case} $\\{cur\_cmd}$ \1\&{of}\6
\4$\\{letter},\39\\{other\_char},\39\\{char\_given}$: \37\&{if} $\\{cur\_chr}%
\G128$ \1\&{then}\5
$\|c\K\\{cur\_chr}$\6
\4\&{else} \&{begin} \37$\|c\K\\{ho}(\\{math\_code}(\\{cur\_chr}))$;\6
\&{if} $\|c=\O{100000}$ \1\&{then}\6
\&{begin} \37\X1152:Treat \\{cur\_chr} as an active character\X;\6
\&{goto} \37\\{restart};\6
\&{end};\2\6
\&{end};\2\6
\4\\{char\_num}: \37\&{begin} \37\\{scan\_char\_num};\5
$\\{cur\_chr}\K\\{cur\_val}$;\5
$\\{cur\_cmd}\K\\{char\_given}$;\5
\&{goto} \37\\{reswitch};\6
\&{end};\6
\4\\{math\_char\_num}: \37\&{begin} \37\\{scan\_fifteen\_bit\_int};\5
$\|c\K\\{cur\_val}$;\6
\&{end};\6
\4\\{math\_given}: \37$\|c\K\\{cur\_chr}$;\6
\4\\{delim\_num}: \37\&{begin} \37\\{scan\_twenty\_seven\_bit\_int};\5
$\|c\K\\{cur\_val}\mathbin{\&{div}}\O{10000}$;\6
\&{end};\6
\4\&{othercases} \37\X1153:Scan a subformula enclosed in braces and \&{return}%
\X\2\6
\&{endcases};\6
$\\{math\_type}(\|p)\K\\{math\_char}$;\5
$\\{character}(\|p)\K\\{qi}(\|c\mathbin{\&{mod}}256)$;\6
\&{if} $(\|c\G\\{var\_code})\W\\{fam\_in\_range}$ \1\&{then}\5
$\\{fam}(\|p)\K\\{cur\_fam}$\6
\4\&{else} $\\{fam}(\|p)\K(\|c\mathbin{\&{div}}256)\mathbin{\&{mod}}16$;\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M1152. An active character that is an \\{outer\_call} is allowed here.

\Y\P$\4\X1152:Treat \\{cur\_chr} as an active character\X\S$\6
\&{begin} \37$\\{cur\_cs}\K\\{cur\_chr}+\\{active\_base}$;\5
$\\{cur\_cmd}\K\\{eq\_type}(\\{cur\_cs})$;\5
$\\{cur\_chr}\K\\{equiv}(\\{cur\_cs})$;\5
\\{x\_token};\5
\\{back\_input};\6
\&{end}\par
\U sections~1151 and~1155.\fi

\M1153. The pointer \|p is placed on \\{save\_stack} while a complex subformula
is being scanned.

\Y\P$\4\X1153:Scan a subformula enclosed in braces and \&{return}\X\S$\6
\&{begin} \37\\{back\_input};\5
\\{scan\_left\_brace};\6
$\\{saved}(0)\K\|p$;\5
$\\{incr}(\\{save\_ptr})$;\5
$\\{push\_math}(\\{math\_group})$;\5
\&{return};\6
\&{end}\par
\U section~1151.\fi

\M1154. The simplest math formula is, of course, `\.{\${ }\$}', when no noads
are
generated. The next simplest cases involve a single character, e.g.,
`\.{\$x\$}'. Even though such cases may not seem to be very interesting,
the reader can perhaps understand how happy the author was when `\.{\$x\$}'
was first properly typeset by \TeX. The code in this section was used.

\Y\P$\4\X1056:Cases of \\{main\_control} that build boxes and lists\X%
\mathrel{+}\S$\6
\4$\\{mmode}+\\{letter},\39\\{mmode}+\\{other\_char},\39\\{mmode}+\\{char%
\_given}$: \37\&{if} $\\{cur\_chr}<128$ \1\&{then}\5
$\\{set\_math\_char}(\\{ho}(\\{math\_code}(\\{cur\_chr})))$\6
\4\&{else} $\\{set\_math\_char}(\\{cur\_chr})$;\2\6
\4$\\{mmode}+\\{char\_num}$: \37\&{begin} \37\\{scan\_char\_num};\5
$\\{cur\_chr}\K\\{cur\_val}$;\6
\&{if} $\\{cur\_chr}<128$ \1\&{then}\5
$\\{set\_math\_char}(\\{ho}(\\{math\_code}(\\{cur\_chr})))$\6
\4\&{else} $\\{set\_math\_char}(\\{cur\_chr})$;\2\6
\&{end};\6
\4$\\{mmode}+\\{math\_char\_num}$: \37\&{begin} \37\\{scan\_fifteen\_bit\_int};%
\5
$\\{set\_math\_char}(\\{cur\_val})$;\6
\&{end};\6
\4$\\{mmode}+\\{math\_given}$: \37$\\{set\_math\_char}(\\{cur\_chr})$;\6
\4$\\{mmode}+\\{delim\_num}$: \37\&{begin} \37\\{scan\_twenty\_seven\_bit%
\_int};\5
$\\{set\_math\_char}(\\{cur\_val}\mathbin{\&{div}}\O{10000})$;\6
\&{end};\par
\fi

\M1155. The \\{set\_math\_char} procedure creates a new noad appropriate to a
given
math code, and appends it to the current mlist. However, if the math code
is sufficiently large, the \\{cur\_chr} is treated as an active character and
nothing is appended.

\Y\P$\4\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{set\_math\_char}(\|c:\\{integer})$;\6
\4\&{var} \37\|p: \37\\{pointer};\C{the new noad}\2\6
\&{begin} \37\&{if} $\|c\G\O{100000}$ \1\&{then}\5
\X1152:Treat \\{cur\_chr} as an active character\X\6
\4\&{else} \&{begin} \37$\|p\K\\{new\_noad}$;\5
$\\{math\_type}(\\{nucleus}(\|p))\K\\{math\_char}$;\5
$\\{character}(\\{nucleus}(\|p))\K\\{qi}(\|c\mathbin{\&{mod}}256)$;\5
$\\{fam}(\\{nucleus}(\|p))\K(\|c\mathbin{\&{div}}256)\mathbin{\&{mod}}16$;\6
\&{if} $\|c\G\\{var\_code}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{fam\_in\_range}$ \1\&{then}\5
$\\{fam}(\\{nucleus}(\|p))\K\\{cur\_fam}$;\2\6
$\\{type}(\|p)\K\\{ord\_noad}$;\6
\&{end}\6
\4\&{else} $\\{type}(\|p)\K\\{ord\_noad}+(\|c\mathbin{\&{div}}\O{10000})$;\2\6
$\\{link}(\\{tail})\K\|p$;\5
$\\{tail}\K\|p$;\6
\&{end};\2\6
\&{end};\par
\fi

\M1156. Primitive math operators like \.{\\mathop} and \.{\\underline} are
given
the command code \\{math\_comp}, supplemented by the noad type that they
generate.

\Y\P$\4\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}\S$\6
$\\{primitive}(\.{"mathord"},\39\\{math\_comp},\39\\{ord\_noad})$;\5
$\\{primitive}(\.{"mathop"},\39\\{math\_comp},\39\\{op\_noad})$;\5
$\\{primitive}(\.{"mathbin"},\39\\{math\_comp},\39\\{bin\_noad})$;\5
$\\{primitive}(\.{"mathrel"},\39\\{math\_comp},\39\\{rel\_noad})$;\5
$\\{primitive}(\.{"mathopen"},\39\\{math\_comp},\39\\{open\_noad})$;\5
$\\{primitive}(\.{"mathclose"},\39\\{math\_comp},\39\\{close\_noad})$;\5
$\\{primitive}(\.{"mathpunct"},\39\\{math\_comp},\39\\{punct\_noad})$;\5
$\\{primitive}(\.{"mathinner"},\39\\{math\_comp},\39\\{inner\_noad})$;\5
$\\{primitive}(\.{"underline"},\39\\{math\_comp},\39\\{under\_noad})$;\5
$\\{primitive}(\.{"overline"},\39\\{math\_comp},\39\\{over\_noad})$;\6
$\\{primitive}(\.{"displaylimits"},\39\\{limit\_switch},\39\\{normal})$;\5
$\\{primitive}(\.{"limits"},\39\\{limit\_switch},\39\\{limits})$;\5
$\\{primitive}(\.{"nolimits"},\39\\{limit\_switch},\39\\{no\_limits})$;\par
\fi

\M1157. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{math\_comp}: \37\&{case} $\\{chr\_code}$ \1\&{of}\6
\4\\{ord\_noad}: \37$\\{print\_esc}(\.{"mathord"})$;\6
\4\\{op\_noad}: \37$\\{print\_esc}(\.{"mathop"})$;\6
\4\\{bin\_noad}: \37$\\{print\_esc}(\.{"mathbin"})$;\6
\4\\{rel\_noad}: \37$\\{print\_esc}(\.{"mathrel"})$;\6
\4\\{open\_noad}: \37$\\{print\_esc}(\.{"mathopen"})$;\6
\4\\{close\_noad}: \37$\\{print\_esc}(\.{"mathclose"})$;\6
\4\\{punct\_noad}: \37$\\{print\_esc}(\.{"mathpunct"})$;\6
\4\\{inner\_noad}: \37$\\{print\_esc}(\.{"mathinner"})$;\6
\4\\{under\_noad}: \37$\\{print\_esc}(\.{"underline"})$;\6
\4\&{othercases} \37$\\{print\_esc}(\.{"overline"})$\2\6
\&{endcases};\6
\4\\{limit\_switch}: \37\&{if} $\\{chr\_code}=\\{limits}$ \1\&{then}\5
$\\{print\_esc}(\.{"limits"})$\6
\4\&{else} \&{if} $\\{chr\_code}=\\{no\_limits}$ \1\&{then}\5
$\\{print\_esc}(\.{"nolimits"})$\6
\4\&{else} $\\{print\_esc}(\.{"displaylimits"})$;\2\2\par
\fi

\M1158. \P$\X1056:Cases of \\{main\_control} that build boxes and lists\X%
\mathrel{+}\S$\6
\4$\\{mmode}+\\{math\_comp}$: \37\&{begin} \37$\\{tail\_append}(\\{new%
\_noad})$;\5
$\\{type}(\\{tail})\K\\{cur\_chr}$;\5
$\\{scan\_math}(\\{nucleus}(\\{tail}))$;\6
\&{end};\6
\4$\\{mmode}+\\{limit\_switch}$: \37\\{math\_limit\_switch};\par
\fi

\M1159. \P$\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{math\_limit\_switch};\6
\4\&{label} \37\\{exit};\2\6
\&{begin} \37\&{if} $\\{head}\I\\{tail}$ \1\&{then}\6
\&{if} $\\{type}(\\{tail})=\\{op\_noad}$ \1\&{then}\6
\&{begin} \37$\\{subtype}(\\{tail})\K\\{cur\_chr}$;\5
\&{return};\6
\&{end};\2\2\6
$\\{print\_err}(\.{"Limit\ controls\ must\ follow\ a\ math\ operator"})$;\5
$\\{help1}(\.{"I\'m\ ignoring\ this\ misplaced\ \\limits\ or\ \\nolimits\
command."})$;\5
\\{error};\6
\4\\{exit}: \37\&{end};\par
\fi

\M1160. Delimiter fields of noads are filled in by the \\{scan\_delimiter}
routine.
The first parameter of this procedure is the \\{mem} address where the
delimiter is to be placed; the second tells if this delimiter follows
\.{\\radical} or not.

\Y\P$\4\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{scan\_delimiter}(\|p:\\{pointer};\,\35\|r:%
\\{boolean})$;\2\6
\&{begin} \37\&{if} $\|r$ \1\&{then}\5
\\{scan\_twenty\_seven\_bit\_int}\6
\4\&{else} \&{begin} \37\X404:Get the next non-blank non-relax non-call token%
\X;\6
\&{case} $\\{cur\_cmd}$ \1\&{of}\6
\4$\\{letter},\39\\{other\_char}$: \37$\\{cur\_val}\K\\{del\_code}(\\{cur%
\_chr})$;\6
\4\\{delim\_num}: \37\\{scan\_twenty\_seven\_bit\_int};\6
\4\&{othercases} \37$\\{cur\_val}\K-1$\2\6
\&{endcases};\6
\&{end};\2\6
\&{if} $\\{cur\_val}<0$ \1\&{then}\5
\X1161:Report that an invalid delimiter code is being changed to null; set~$%
\\{cur\_val}\K0$\X;\2\6
$\\{small\_fam}(\|p)\K(\\{cur\_val}\mathbin{\&{div}}\O{4000000})\mathbin{%
\&{mod}}16$;\5
$\\{small\_char}(\|p)\K\\{qi}((\\{cur\_val}\mathbin{\&{div}}\O{10000})\mathbin{%
\&{mod}}256)$;\5
$\\{large\_fam}(\|p)\K(\\{cur\_val}\mathbin{\&{div}}256)\mathbin{\&{mod}}16$;\5
$\\{large\_char}(\|p)\K\\{qi}(\\{cur\_val}\mathbin{\&{mod}}256)$;\6
\&{end};\par
\fi

\M1161. \P$\X1161:Report that an invalid delimiter code is being changed to
null; set~$\\{cur\_val}\K0$\X\S$\6
\&{begin} \37$\\{print\_err}(\.{"Missing\ delimiter\ (.\ inserted)"})$;\5
$\\{help6}(\.{"I\ was\ expecting\ to\ see\ something\ like\ \`(\'\ or\ \`\\\{\'%
\ or"})$\6
$(\.{"\`\\\}\'\ here.\ If\ you\ typed,\ e.g.,\ \`\{\'\ instead\ of\ \`\\\{\',\
you"})$\6
$(\.{"should\ probably\ delete\ the\ \`\{\'\ by\ typing\ \`1\'\ now,\ so\
that"})$\6
$(\.{"braces\ don\'t\ get\ unbalanced.\ Otherwise\ just\ proceed."})$\6
$(\.{"Acceptable\ delimiters\ are\ characters\ whose\ \\delcode\ is"})$\6
$(\.{"nonnegative,\ or\ you\ can\ use\ \`\\delimiter\ <delimiter\ code>\'."})$;%
\5
\\{back\_error};\5
$\\{cur\_val}\K0$;\6
\&{end}\par
\U section~1160.\fi

\M1162. \P$\X1056:Cases of \\{main\_control} that build boxes and lists\X%
\mathrel{+}\S$\6
\4$\\{mmode}+\\{radical}$: \37\\{math\_radical};\par
\fi

\M1163. \P$\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{math\_radical};\2\6
\&{begin} \37$\\{tail\_append}(\\{get\_node}(\\{radical\_noad\_size}))$;\5
$\\{type}(\\{tail})\K\\{radical\_noad}$;\5
$\\{subtype}(\\{tail})\K\\{normal}$;\5
$\\{mem}[\\{nucleus}(\\{tail})].\\{hh}\K\\{empty\_field}$;\5
$\\{mem}[\\{subscr}(\\{tail})].\\{hh}\K\\{empty\_field}$;\5
$\\{mem}[\\{supscr}(\\{tail})].\\{hh}\K\\{empty\_field}$;\5
$\\{scan\_delimiter}(\\{left\_delimiter}(\\{tail}),\39\\{true})$;\5
$\\{scan\_math}(\\{nucleus}(\\{tail}))$;\6
\&{end};\par
\fi

\M1164. \P$\X1056:Cases of \\{main\_control} that build boxes and lists\X%
\mathrel{+}\S$\6
\4$\\{mmode}+\\{accent},\39\\{mmode}+\\{math\_accent}$: \37\\{math\_ac};\par
\fi

\M1165. \P$\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{math\_ac};\2\6
\&{begin} \37\&{if} $\\{cur\_cmd}=\\{accent}$ \1\&{then}\5
\X1166:Complain that the user should have said \.{\\mathaccent}\X;\2\6
$\\{tail\_append}(\\{get\_node}(\\{accent\_noad\_size}))$;\5
$\\{type}(\\{tail})\K\\{accent\_noad}$;\5
$\\{subtype}(\\{tail})\K\\{normal}$;\5
$\\{mem}[\\{nucleus}(\\{tail})].\\{hh}\K\\{empty\_field}$;\5
$\\{mem}[\\{subscr}(\\{tail})].\\{hh}\K\\{empty\_field}$;\5
$\\{mem}[\\{supscr}(\\{tail})].\\{hh}\K\\{empty\_field}$;\5
$\\{math\_type}(\\{accent\_chr}(\\{tail}))\K\\{math\_char}$;\5
\\{scan\_fifteen\_bit\_int};\5
$\\{character}(\\{accent\_chr}(\\{tail}))\K\\{qi}(\\{cur\_val}\mathbin{%
\&{mod}}256)$;\6
\&{if} $(\\{cur\_val}\G\\{var\_code})\W\\{fam\_in\_range}$ \1\&{then}\5
$\\{fam}(\\{accent\_chr}(\\{tail}))\K\\{cur\_fam}$\6
\4\&{else} $\\{fam}(\\{accent\_chr}(\\{tail}))\K(\\{cur\_val}\mathbin{%
\&{div}}256)\mathbin{\&{mod}}16$;\2\6
$\\{scan\_math}(\\{nucleus}(\\{tail}))$;\6
\&{end};\par
\fi

\M1166. \P$\X1166:Complain that the user should have said \.{\\mathaccent}\X\S$%
\6
\&{begin} \37$\\{print\_err}(\.{"Please\ use\ "})$;\5
$\\{print\_esc}(\.{"mathaccent"})$;\5
$\\{print}(\.{"\ for\ accents\ in\ math\ mode"})$;\5
$\\{help2}(\.{"I\'m\ changing\ \\accent\ to\ \\mathaccent\ here;\ wish\ me\
luck."})$\6
$(\.{"(Accents\ are\ not\ the\ same\ in\ formulas\ as\ they\ are\ in\
text.)"})$;\5
\\{error};\6
\&{end}\par
\U section~1165.\fi

\M1167. \P$\X1056:Cases of \\{main\_control} that build boxes and lists\X%
\mathrel{+}\S$\6
\4$\\{mmode}+\\{vcenter}$: \37\&{begin} \37\\{scan\_spec};\5
$\\{new\_save\_level}(\\{vcenter\_group})$;\5
\\{normal\_paragraph};\5
\\{push\_nest};\5
$\\{mode}\K-\\{vmode}$;\5
$\\{prev\_depth}\K\\{ignore\_depth}$;\6
\&{if} $\\{every\_vbox}\I\\{null}$ \1\&{then}\5
$\\{begin\_token\_list}(\\{every\_vbox},\39\\{every\_vbox\_text})$;\2\6
\&{end};\par
\fi

\M1168. \P$\X1085:Cases of \\{handle\_right\_brace} where a \\{right\_brace}
triggers a delayed action\X\mathrel{+}\S$\6
\4\\{vcenter\_group}: \37\&{begin} \37\\{end\_graf};\5
\\{unsave};\5
$\\{save\_ptr}\K\\{save\_ptr}-2$;\5
$\|p\K\\{vpack}(\\{link}(\\{head}),\39\\{saved}(1),\39\\{saved}(0))$;\5
\\{pop\_nest};\5
$\\{tail\_append}(\\{new\_noad})$;\5
$\\{type}(\\{tail})\K\\{vcenter\_noad}$;\5
$\\{math\_type}(\\{nucleus}(\\{tail}))\K\\{sub\_box}$;\5
$\\{info}(\\{nucleus}(\\{tail}))\K\|p$;\6
\&{end};\par
\fi

\M1169. The routine that inserts a \\{style\_node} holds no surprises.

\Y\P$\4\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}\S$\6
$\\{primitive}(\.{"displaystyle"},\39\\{math\_style},\39\\{display\_style})$;\5
$\\{primitive}(\.{"textstyle"},\39\\{math\_style},\39\\{text\_style})$;\5
$\\{primitive}(\.{"scriptstyle"},\39\\{math\_style},\39\\{script\_style})$;\5
$\\{primitive}(\.{"scriptscriptstyle"},\39\\{math\_style},\39\\{script\_script%
\_style})$;\par
\fi

\M1170. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{math\_style}: \37$\\{print\_style}(\\{chr\_code})$;\par
\fi

\M1171. \P$\X1056:Cases of \\{main\_control} that build boxes and lists\X%
\mathrel{+}\S$\6
\4$\\{mmode}+\\{math\_style}$: \37$\\{tail\_append}(\\{new\_style}(\\{cur%
\_chr}))$;\6
\4$\\{mmode}+\\{non\_script}$: \37\&{begin} \37$\\{tail\_append}(\\{new\_glue}(%
\\{zero\_glue}))$;\5
$\\{subtype}(\\{tail})\K\\{cond\_math\_glue}$;\6
\&{end};\6
\4$\\{mmode}+\\{math\_choice}$: \37\\{append\_choices};\par
\fi

\M1172. The routine that scans the four mlists of a \.{\\mathchoice} is very
much like the routine that builds discretionary nodes.

\Y\P$\4\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{append\_choices};\2\6
\&{begin} \37$\\{tail\_append}(\\{new\_choice})$;\5
$\\{incr}(\\{save\_ptr})$;\5
$\\{saved}(-1)\K0$;\5
\\{scan\_left\_brace};\5
$\\{push\_math}(\\{math\_choice\_group})$;\6
\&{end};\par
\fi

\M1173. \P$\X1085:Cases of \\{handle\_right\_brace} where a \\{right\_brace}
triggers a delayed action\X\mathrel{+}\S$\6
\4\\{math\_choice\_group}: \37\\{build\_choices};\par
\fi

\M1174. \P$\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\hbox{\4}\X1184:Declare the function called \\{fin\_mlist}\X\hbox{}\6
\4\&{procedure}\1\  \37\\{build\_choices};\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37\|p: \37\\{pointer};\C{the current mlist}\2\6
\&{begin} \37\\{unsave};\5
$\|p\K\\{fin\_mlist}(\\{null})$;\6
\&{case} $\\{saved}(-1)$ \1\&{of}\6
\40: \37$\\{display\_mlist}(\\{tail})\K\|p$;\6
\41: \37$\\{text\_mlist}(\\{tail})\K\|p$;\6
\42: \37$\\{script\_mlist}(\\{tail})\K\|p$;\6
\43: \37\&{begin} \37$\\{script\_script\_mlist}(\\{tail})\K\|p$;\5
$\\{decr}(\\{save\_ptr})$;\5
\&{return};\6
\&{end};\2\6
\&{end};\C{there are no other cases}\6
$\\{incr}(\\{saved}(-1))$;\5
\\{scan\_left\_brace};\5
$\\{push\_math}(\\{math\_choice\_group})$;\6
\4\\{exit}: \37\&{end};\par
\fi

\M1175. Subscripts and superscripts are attached to the previous nucleus by the
action procedure called \\{sub\_sup}. We use the facts that $\\{sub\_mark}=%
\\{sup\_mark}+1$
and $\\{subscr}(\|p)=\\{supscr}(\|p)+1$.

\Y\P$\4\X1056:Cases of \\{main\_control} that build boxes and lists\X%
\mathrel{+}\S$\6
\4$\\{mmode}+\\{sub\_mark},\39\\{mmode}+\\{sup\_mark}$: \37\\{sub\_sup};\par
\fi

\M1176. \P$\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{sub\_sup};\6
\4\&{var} \37\|t: \37\\{small\_number};\C{type of previous sub/superscript}\6
\|p: \37\\{pointer};\C{field to be filled by \\{scan\_math}}\2\6
\&{begin} \37$\|t\K\\{empty}$;\5
$\|p\K\\{null}$;\6
\&{if} $\\{tail}\I\\{head}$ \1\&{then}\6
\&{if} $\\{scripts\_allowed}(\\{tail})$ \1\&{then}\6
\&{begin} \37$\|p\K\\{supscr}(\\{tail})+\\{cur\_cmd}-\\{sup\_mark}$;\C{%
\\{supscr} or \\{subscr}}\6
$\|t\K\\{math\_type}(\|p)$;\6
\&{end};\2\2\6
\&{if} $(\|p=\\{null})\V(\|t\I\\{empty})$ \1\&{then}\5
\X1177:Insert a dummy noad to be sub/superscripted\X;\2\6
$\\{scan\_math}(\|p)$;\6
\&{end};\par
\fi

\M1177. \P$\X1177:Insert a dummy noad to be sub/superscripted\X\S$\6
\&{begin} \37$\\{tail\_append}(\\{new\_noad})$;\5
$\|p\K\\{supscr}(\\{tail})+\\{cur\_cmd}-\\{sup\_mark}$;\C{\\{supscr} or %
\\{subscr}}\6
\&{if} $\|t\I\\{empty}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{cur\_cmd}=\\{sup\_mark}$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Double\ superscript"})$;\5
$\\{help1}(\.{"I\ treat\ \`x\↑1\↑2\'\ essentially\ like\ \`x\↑1\{\}\↑2\'."})$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{print\_err}(\.{"Double\ subscript"})$;\5
$\\{help1}(\.{"I\ treat\ \`x\_1\_2\'\ essentially\ like\ \`x\_1\{\}\_2\'."})$;\6
\&{end};\2\6
\\{error};\6
\&{end};\2\6
\&{end}\par
\U section~1176.\fi

\M1178. An operation like `\.{\\over}' causes the current mlist to go into a
state of suspended animation: \\{incompleat\_noad} points to a \\{fraction%
\_noad}
that contains the mlist-so-far as its numerator, while the denominator
is yet to come. Finally when the mlist is finished, the denominator will
go into the incompleat fraction noad, and that noad will become the
whole formula, unless it is surrounded by `\.{\\left}' and `\.{\\right}'
delimiters.

\Y\P\D \37$\\{above\_code}=0$\C{ `\.{\\above}' }\par
\P\D \37$\\{over\_code}=1$\C{ `\.{\\over}' }\par
\P\D \37$\\{atop\_code}=2$\C{ `\.{\\atop}' }\par
\P\D \37$\\{delimited\_code}=3$\C{ `\.{\\abovewithdelims}', etc.}\par
\Y\P$\4\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}\S$\6
$\\{primitive}(\.{"above"},\39\\{above},\39\\{above\_code})$;\6
$\\{primitive}(\.{"over"},\39\\{above},\39\\{over\_code})$;\6
$\\{primitive}(\.{"atop"},\39\\{above},\39\\{atop\_code})$;\6
$\\{primitive}(\.{"abovewithdelims"},\39\\{above},\39\\{delimited\_code}+%
\\{above\_code})$;\6
$\\{primitive}(\.{"overwithdelims"},\39\\{above},\39\\{delimited\_code}+\\{over%
\_code})$;\6
$\\{primitive}(\.{"atopwithdelims"},\39\\{above},\39\\{delimited\_code}+\\{atop%
\_code})$;\par
\fi

\M1179. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{above}: \37\&{case} $\\{chr\_code}$ \1\&{of}\6
\4\\{over\_code}: \37$\\{print\_esc}(\.{"over"})$;\6
\4\\{atop\_code}: \37$\\{print\_esc}(\.{"atop"})$;\6
\4$\\{delimited\_code}+\\{above\_code}$: \37$\\{print\_esc}(%
\.{"abovewithdelims"})$;\6
\4$\\{delimited\_code}+\\{over\_code}$: \37$\\{print\_esc}(%
\.{"overwithdelims"})$;\6
\4$\\{delimited\_code}+\\{atop\_code}$: \37$\\{print\_esc}(%
\.{"atopwithdelims"})$;\6
\4\&{othercases} \37$\\{print\_esc}(\.{"above"})$\2\6
\&{endcases};\par
\fi

\M1180. \P$\X1056:Cases of \\{main\_control} that build boxes and lists\X%
\mathrel{+}\S$\6
\4$\\{mmode}+\\{above}$: \37\\{math\_fraction};\par
\fi

\M1181. \P$\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{math\_fraction};\6
\4\&{var} \37\|c: \37\\{small\_number};\C{the type of generalized fraction we
are scanning}\2\6
\&{begin} \37$\|c\K\\{cur\_chr}$;\6
\&{if} $\\{incompleat\_noad}\I\\{null}$ \1\&{then}\5
\X1183:Ignore the fraction operation and complain about this ambiguous case\X\6
\4\&{else} \&{begin} \37$\\{incompleat\_noad}\K\\{get\_node}(\\{fraction\_noad%
\_size})$;\5
$\\{type}(\\{incompleat\_noad})\K\\{fraction\_noad}$;\5
$\\{subtype}(\\{incompleat\_noad})\K\\{normal}$;\5
$\\{math\_type}(\\{numerator}(\\{incompleat\_noad}))\K\\{sub\_mlist}$;\5
$\\{info}(\\{numerator}(\\{incompleat\_noad}))\K\\{link}(\\{head})$;\5
$\\{mem}[\\{denominator}(\\{incompleat\_noad})].\\{hh}\K\\{empty\_field}$;\5
$\\{mem}[\\{left\_delimiter}(\\{incompleat\_noad})].\\{qqqq}\K\\{null%
\_delimiter}$;\5
$\\{mem}[\\{right\_delimiter}(\\{incompleat\_noad})].\\{qqqq}\K\\{null%
\_delimiter}$;\6
$\\{link}(\\{head})\K\\{null}$;\5
$\\{tail}\K\\{head}$;\5
\X1182:Use code \|c to distinguish between generalized fractions\X;\6
\&{end};\2\6
\&{end};\par
\fi

\M1182. \P$\X1182:Use code \|c to distinguish between generalized fractions\X%
\S$\6
\&{if} $\|c\G\\{delimited\_code}$ \1\&{then}\6
\&{begin} \37$\\{scan\_delimiter}(\\{left\_delimiter}(\\{incompleat\_noad}),\39%
\\{false})$;\5
$\\{scan\_delimiter}(\\{right\_delimiter}(\\{incompleat\_noad}),\39\\{false})$;%
\6
\&{end};\2\6
\&{case} $\|c\mathbin{\&{mod}}\\{delimited\_code}$ \1\&{of}\6
\4\\{above\_code}: \37\&{begin} \37\\{scan\_normal\_dimen};\5
$\\{thickness}(\\{incompleat\_noad})\K\\{cur\_val}$;\6
\&{end};\6
\4\\{over\_code}: \37$\\{thickness}(\\{incompleat\_noad})\K\\{default\_code}$;\6
\4\\{atop\_code}: \37$\\{thickness}(\\{incompleat\_noad})\K0$;\2\6
\&{end}\C{there are no other cases}\par
\U section~1181.\fi

\M1183. \P$\X1183:Ignore the fraction operation and complain about this
ambiguous case\X\S$\6
\&{begin} \37\&{if} $\|c\G\\{delimited\_code}$ \1\&{then}\6
\&{begin} \37$\\{scan\_delimiter}(\\{garbage},\39\\{false})$;\5
$\\{scan\_delimiter}(\\{garbage},\39\\{false})$;\6
\&{end};\2\6
\&{if} $\|c\mathbin{\&{mod}}\\{delimited\_code}=\\{above\_code}$ \1\&{then}\5
\\{scan\_normal\_dimen};\2\6
$\\{print\_err}(\.{"Ambiguous;\ you\ need\ another\ \{\ and\ \}"})$;\5
$\\{help3}(\.{"I\'m\ ignoring\ this\ fraction\ specification,\ since\ I\ don%
\'t"})$\6
$(\.{"know\ whether\ a\ construction\ like\ \`x\ \\over\ y\ \\over\ z\'"})$\6
$(\.{"means\ \`\{x\ \\over\ y\}\ \\over\ z\'\ or\ \`x\ \\over\ \{y\ \\over\ z\}%
\'."})$;\5
\\{error};\6
\&{end}\par
\U section~1181.\fi

\M1184. At the end of a math formula or subformula, the \\{fin\_mlist} routine
is
called upon to return a pointer to the newly completed mlist, and to
pop the nest back to the enclosing semantic level. The parameter to
\\{fin\_mlist}, if not null, points to a \\{right\_noad} that ends the
current mlist; this \\{right\_noad} has not yet been appended.

\Y\P$\4\X1184:Declare the function called \\{fin\_mlist}\X\S$\6
\4\&{function}\1\  \37$\\{fin\_mlist}(\|p:\\{pointer})$: \37\\{pointer};\6
\4\&{var} \37\|q: \37\\{pointer};\C{the mlist to return}\2\6
\&{begin} \37\&{if} $\\{incompleat\_noad}\I\\{null}$ \1\&{then}\5
\X1185:Compleat the incompleat noad\X\6
\4\&{else} \&{begin} \37$\\{link}(\\{tail})\K\|p$;\5
$\|q\K\\{link}(\\{head})$;\6
\&{end};\2\6
\\{pop\_nest};\5
$\\{fin\_mlist}\K\|q$;\6
\&{end};\par
\U section~1174.\fi

\M1185. \P$\X1185:Compleat the incompleat noad\X\S$\6
\&{begin} \37$\\{math\_type}(\\{denominator}(\\{incompleat\_noad}))\K\\{sub%
\_mlist}$;\5
$\\{info}(\\{denominator}(\\{incompleat\_noad}))\K\\{link}(\\{head})$;\6
\&{if} $\|p=\\{null}$ \1\&{then}\5
$\|q\K\\{incompleat\_noad}$\6
\4\&{else} \&{begin} \37$\|q\K\\{info}(\\{numerator}(\\{incompleat\_noad}))$;\6
\&{if} $\\{type}(\|q)\I\\{left\_noad}$ \1\&{then}\5
$\\{confusion}(\.{"right"})$;\2\6
$\\{info}(\\{numerator}(\\{incompleat\_noad}))\K\\{link}(\|q)$;\5
$\\{link}(\|q)\K\\{incompleat\_noad}$;\5
$\\{link}(\\{incompleat\_noad})\K\|p$;\6
\&{end};\2\6
\&{end}\par
\U section~1184.\fi

\M1186. Now at last we're ready to see what happens when a right brace occurs
in a math formula. Two special cases are simplified here: Braces are
effectively
removed when they surround a single Ord character or, when they
surround an accent that is the nucleus of an Ord atom.

\Y\P$\4\X1085:Cases of \\{handle\_right\_brace} where a \\{right\_brace}
triggers a delayed action\X\mathrel{+}\S$\6
\4\\{math\_group}: \37\&{begin} \37\\{unsave};\5
$\\{decr}(\\{save\_ptr})$;\6
$\\{math\_type}(\\{saved}(0))\K\\{sub\_mlist}$;\5
$\|p\K\\{fin\_mlist}(\\{null})$;\5
$\\{info}(\\{saved}(0))\K\|p$;\6
\&{if} $\|p\I\\{null}$ \1\&{then}\6
\&{if} $\\{link}(\|p)=\\{null}$ \1\&{then}\6
\&{if} $\\{type}(\|p)=\\{ord\_noad}$ \1\&{then}\6
\&{begin} \37\&{if} $\\{math\_type}(\\{subscr}(\|p))=\\{empty}$ \1\&{then}\6
\&{if} $\\{math\_type}(\\{supscr}(\|p))=\\{empty}$ \1\&{then}\6
\&{begin} \37$\\{mem}[\\{saved}(0)].\\{hh}\K\\{mem}[\\{nucleus}(\|p)].\\{hh}$;\5
$\\{free\_node}(\|p,\39\\{noad\_size})$;\6
\&{end};\2\2\6
\&{end}\6
\4\&{else} \&{if} $\\{type}(\|p)=\\{accent\_noad}$ \1\&{then}\6
\&{if} $\\{saved}(0)=\\{nucleus}(\\{tail})$ \1\&{then}\6
\&{if} $\\{type}(\\{tail})=\\{ord\_noad}$ \1\&{then}\5
\X1187:Replace the tail of the list by \|p\X;\2\2\2\2\2\2\6
\&{end};\par
\fi

\M1187. \P$\X1187:Replace the tail of the list by \|p\X\S$\6
\&{begin} \37$\|q\K\\{head}$;\6
\&{while} $\\{link}(\|q)\I\\{tail}$ \1\&{do}\5
$\|q\K\\{link}(\|q)$;\2\6
$\\{link}(\|q)\K\|p$;\5
$\\{free\_node}(\\{tail},\39\\{noad\_size})$;\5
$\\{tail}\K\|p$;\6
\&{end}\par
\U section~1186.\fi

\M1188. We have dealt with all constructions of math mode except `\.{\\left}'
and
`\.{\\right}', so the picture is completed by the following sections of
the program.

\Y\P$\4\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}\S$\6
$\\{primitive}(\.{"left"},\39\\{left\_right},\39\\{left\_noad})$;\5
$\\{primitive}(\.{"right"},\39\\{left\_right},\39\\{right\_noad})$;\5
$\\{text}(\\{frozen\_right})\K\.{"right"}$;\5
$\\{eqtb}[\\{frozen\_right}]\K\\{eqtb}[\\{cur\_val}]$;\par
\fi

\M1189. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{left\_right}: \37\&{if} $\\{chr\_code}=\\{left\_noad}$ \1\&{then}\5
$\\{print\_esc}(\.{"left"})$\6
\4\&{else} $\\{print\_esc}(\.{"right"})$;\2\par
\fi

\M1190. \P$\X1056:Cases of \\{main\_control} that build boxes and lists\X%
\mathrel{+}\S$\6
\4$\\{mmode}+\\{left\_right}$: \37\\{math\_left\_right};\par
\fi

\M1191. \P$\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{math\_left\_right};\6
\4\&{var} \37\|t: \37\\{small\_number};\C{\\{left\_noad} or \\{right\_noad}}\6
\|p: \37\\{pointer};\C{new noad}\2\6
\&{begin} \37$\|t\K\\{cur\_chr}$;\6
\&{if} $(\|t=\\{right\_noad})\W(\\{cur\_group}\I\\{math\_left\_group})$ \1%
\&{then}\5
\X1192:Try to recover from mismatched \.{\\right}\X\6
\4\&{else} \&{begin} \37$\|p\K\\{new\_noad}$;\5
$\\{type}(\|p)\K\|t$;\5
$\\{scan\_delimiter}(\\{delimiter}(\|p),\39\\{false})$;\6
\&{if} $\|t=\\{left\_noad}$ \1\&{then}\6
\&{begin} \37$\\{push\_math}(\\{math\_left\_group})$;\5
$\\{link}(\\{head})\K\|p$;\5
$\\{tail}\K\|p$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\|p\K\\{fin\_mlist}(\|p)$;\5
\\{unsave};\C{end of \\{math\_left\_group}}\6
$\\{tail\_append}(\\{new\_noad})$;\5
$\\{type}(\\{tail})\K\\{inner\_noad}$;\5
$\\{math\_type}(\\{nucleus}(\\{tail}))\K\\{sub\_mlist}$;\5
$\\{info}(\\{nucleus}(\\{tail}))\K\|p$;\6
\&{end};\2\6
\&{end};\2\6
\&{end};\par
\fi

\M1192. \P$\X1192:Try to recover from mismatched \.{\\right}\X\S$\6
\&{begin} \37\&{if} $\\{cur\_group}=\\{math\_shift\_group}$ \1\&{then}\6
\&{begin} \37$\\{scan\_delimiter}(\\{garbage},\39\\{false})$;\5
$\\{print\_err}(\.{"Extra\ "})$;\5
$\\{print\_esc}(\.{"right"})$;\5
$\\{help1}(\.{"I\'m\ ignoring\ a\ \\right\ that\ had\ no\ matching\ %
\\left."})$;\5
\\{error};\6
\&{end}\6
\4\&{else} \\{off\_save};\2\6
\&{end}\par
\U section~1191.\fi

\M1193. Here is the only way out of math mode.

\Y\P$\4\X1056:Cases of \\{main\_control} that build boxes and lists\X%
\mathrel{+}\S$\6
\4$\\{mmode}+\\{math\_shift}$: \37\&{if} $\\{cur\_group}=\\{math\_shift%
\_group}$ \1\&{then}\5
\\{after\_math}\6
\4\&{else} \\{off\_save};\2\par
\fi

\M1194. \P$\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{after\_math};\6
\4\&{var} \37\|l: \37\\{boolean};\C{`\.{\\leqno}' instead of `\.{\\eqno}'}\6
\\{danger}: \37\\{boolean};\C{not enough symbol fonts are present}\6
\|m: \37\\{integer};\C{\\{mmode} or $-\\{mmode}$}\6
\|p: \37\\{pointer};\C{the formula}\6
\|a: \37\\{pointer};\C{box containing equation number}\6
\X1198:Local variables for finishing a displayed formula\X\2\6
\&{begin} \37$\\{danger}\K\\{false}$;\5
\X1195:Check that the necessary fonts for math symbols are present; if not,
flush the current math lists and set $\\{danger}\K\\{true}$\X;\6
$\|m\K\\{mode}$;\5
$\|l\K\\{false}$;\5
$\|p\K\\{fin\_mlist}(\\{null})$;\C{this pops the nest}\6
\&{if} $\\{mode}=-\|m$ \1\&{then}\C{end of equation number}\6
\&{begin} \37$\\{cur\_mlist}\K\|p$;\5
$\\{cur\_style}\K\\{text\_style}$;\5
$\\{mlist\_penalties}\K\\{false}$;\5
\\{mlist\_to\_hlist};\5
$\|a\K\\{hpack}(\\{link}(\\{temp\_head}),\39\\{natural})$;\5
\\{unsave};\5
$\\{decr}(\\{save\_ptr})$;\C{now $\\{cur\_group}=\\{math\_shift\_group}$}\6
\&{if} $\\{saved}(0)=1$ \1\&{then}\5
$\|l\K\\{true}$;\2\6
\&{if} $\\{danger}$ \1\&{then}\5
\\{flush\_math};\2\6
$\|m\K\\{mode}$;\5
$\|p\K\\{fin\_mlist}(\\{null})$;\6
\&{end}\6
\4\&{else} $\|a\K\\{null}$;\2\6
\&{if} $\|m<0$ \1\&{then}\5
\X1196:Finish math in text\X\6
\4\&{else} \&{begin} \37\X1197:Check that another \.\$ follows\X;\6
\X1199:Finish displayed math\X;\6
\&{end};\2\6
\&{end};\par
\fi

\M1195. \P$\X1195:Check that the necessary fonts for math symbols are present;
if not, flush the current math lists and set $\\{danger}\K\\{true}$\X\S$\6
\&{if} $(\\{font\_params}[\\{fam\_fnt}(2+\\{text\_size})]<\\{total\_mathsy%
\_params})\V\30(\\{font\_params}[\\{fam\_fnt}(2+\\{script\_size})]<\\{total%
\_mathsy\_params})\V\30(\\{font\_params}[\\{fam\_fnt}(2+\\{script\_script%
\_size})]<\\{total\_mathsy\_params})$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Math\ formula\ deleted:\ Insufficient\ symbol\
fonts"})$;\6
$\\{help3}(\.{"Sorry,\ but\ I\ can\'t\ typeset\ math\ unless\ \\textfont\ 2"})$%
\6
$(\.{"and\ \\scriptfont\ 2\ and\ \\scriptscriptfont\ 2\ have\ all"})$\6
$(\.{"the\ \\fontdimen\ values\ needed\ in\ math\ symbol\ fonts."})$;\5
\\{error};\5
\\{flush\_math};\5
$\\{danger}\K\\{true}$;\6
\&{end}\6
\4\&{else} \&{if} $(\\{font\_params}[\\{fam\_fnt}(3+\\{text\_size})]<\\{total%
\_mathex\_params})\V\30(\\{font\_params}[\\{fam\_fnt}(3+\\{script\_size})]<%
\\{total\_mathex\_params})\V\30(\\{font\_params}[\\{fam\_fnt}(3+\\{script%
\_script\_size})]<\\{total\_mathex\_params})$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Math\ formula\ deleted:\ Insufficient\
extension\ fonts"})$;\6
$\\{help3}(\.{"Sorry,\ but\ I\ can\'t\ typeset\ math\ unless\ \\textfont\ 3"})$%
\6
$(\.{"and\ \\scriptfont\ 3\ and\ \\scriptscriptfont\ 3\ have\ all"})$\6
$(\.{"the\ \\fontdimen\ values\ needed\ in\ math\ extension\ fonts."})$;\5
\\{error};\5
\\{flush\_math};\5
$\\{danger}\K\\{true}$;\6
\&{end}\2\2\par
\U section~1194.\fi

\M1196. The \\{unsave} is done after everything else here; therefore an
appearance of
`\.{\\mathsurround}' inside of `\.{\$...\$}' affects the spacing at these
particular \.\$'s. This is consistent with the conventions of
`\.{\$\$...\$\$}', since `\.{\\abovedisplayskip}' inside a display affects the
space above that display.

\Y\P$\4\X1196:Finish math in text\X\S$\6
\&{begin} \37$\\{tail\_append}(\\{new\_math}(\\{math\_surround},\39%
\\{before}))$;\5
$\\{cur\_mlist}\K\|p$;\5
$\\{cur\_style}\K\\{text\_style}$;\5
$\\{mlist\_penalties}\K(\\{mode}>0)$;\5
\\{mlist\_to\_hlist};\5
$\\{link}(\\{tail})\K\\{link}(\\{temp\_head})$;\6
\&{while} $\\{link}(\\{tail})\I\\{null}$ \1\&{do}\5
$\\{tail}\K\\{link}(\\{tail})$;\2\6
$\\{tail\_append}(\\{new\_math}(\\{math\_surround},\39\\{after}))$;\5
$\\{space\_factor}\K1000$;\5
\\{unsave};\6
\&{end}\par
\U section~1194.\fi

\M1197. \TeX\ gets to the following part of the program when the first `\.\$'
ending
a display has been scanned.

\Y\P$\4\X1197:Check that another \.\$ follows\X\S$\6
\&{begin} \37\\{get\_x\_token};\6
\&{if} $\\{cur\_cmd}\I\\{math\_shift}$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Display\ math\ should\ end\ with\ \$\$"})$;\5
$\\{help2}(\.{"The\ \`\$\'\ that\ I\ just\ saw\ supposedly\ matches\ a\
previous\ \`\$\$\'."})$\6
$(\.{"So\ I\ shall\ assume\ that\ you\ typed\ \`\$\$\'\ both\ times."})$;\5
\\{back\_error};\6
\&{end};\2\6
\&{end}\par
\U sections~1194 and~1206.\fi

\M1198. We have saved the worst for last: The fussiest part of math mode
processing
occurs when a displayed formula is being centered and placed with an optional
equation number.

\Y\P$\4\X1198:Local variables for finishing a displayed formula\X\S$\6
\4\|b: \37\\{pointer};\C{box containing the equation}\6
\4\|w: \37\\{scaled};\C{width of the equation}\6
\4\|z: \37\\{scaled};\C{width of the line}\6
\4\|e: \37\\{scaled};\C{width of equation number}\6
\4\|q: \37\\{scaled};\C{width of equation number plus space to separate from
equation}\6
\4\|d: \37\\{scaled};\C{displacement of equation in the line}\6
\4\|s: \37\\{scaled};\C{move the line right this much}\6
\4$\\{g1},\39\\{g2}$: \37\\{small\_number};\C{glue parameter codes for before
and after}\6
\4\|r: \37\\{pointer};\C{kern node used to position the display}\6
\4\|t: \37\\{pointer};\C{tail of adjustment list}\par
\U section~1194.\fi

\M1199. At this time \|p points to the mlist for the formula; \|a is either
\\{null} or it points to a box containing the equation number; and we are in
vertical mode (or internal vertical mode).

\Y\P$\4\X1199:Finish displayed math\X\S$\6
$\\{cur\_mlist}\K\|p$;\5
$\\{cur\_style}\K\\{display\_style}$;\5
$\\{mlist\_penalties}\K\\{false}$;\5
\\{mlist\_to\_hlist};\5
$\|p\K\\{link}(\\{temp\_head})$;\6
$\\{adjust\_tail}\K\\{adjust\_head}$;\5
$\|b\K\\{hpack}(\|p,\39\\{natural})$;\5
$\|t\K\\{adjust\_tail}$;\5
$\\{adjust\_tail}\K\\{null}$;\6
$\|w\K\\{width}(\|b)$;\5
$\|z\K\\{display\_width}$;\5
$\|s\K\\{display\_indent}$;\6
\&{if} $(\|a=\\{null})\V\\{danger}$ \1\&{then}\6
\&{begin} \37$\|e\K0$;\5
$\|q\K0$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\|e\K\\{width}(\|a)$;\5
$\|q\K\|e+\\{math\_quad}(\\{text\_size})$;\6
\&{end};\2\6
\&{if} $\|w+\|q>\|z$ \1\&{then}\5
\X1201:Squeeze the equation as much as possible; if there is an equation number
that should go on a separate line by itself, set~$\|e\K0$\X;\2\6
\X1202:Determine the displacement, \|d, of the left edge of the equation, with
respect to the line size \|z, assuming that $\|l=\\{false}$\X;\6
\X1203:Append the glue or equation number preceding the display\X;\6
\X1204:Append the display and perhaps also the equation number\X;\6
\X1205:Append the glue or equation number following the display\X;\6
\\{resume\_after\_display}\par
\U section~1194.\fi

\M1200. \P$\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{resume\_after\_display};\2\6
\&{begin} \37\&{if} $\\{cur\_group}\I\\{math\_shift\_group}$ \1\&{then}\5
$\\{confusion}(\.{"display"})$;\2\6
\\{unsave};\5
$\\{prev\_graf}\K\\{prev\_graf}+3$;\5
\\{push\_nest};\5
$\\{mode}\K\\{hmode}$;\5
$\\{space\_factor}\K1000$;\5
\X443:Scan an optional space\X;\6
\&{if} $\\{nest\_ptr}=1$ \1\&{then}\5
\\{build\_page};\2\6
\&{end};\par
\fi

\M1201. The user can force the equation number to go on a separate line
by making its width zero.

\Y\P$\4\X1201:Squeeze the equation as much as possible; if there is an equation
number that should go on a separate line by itself, set~$\|e\K0$\X\S$\6
\&{begin} \37\&{if} $(\|e\I0)\W((\|w-\\{total\_shrink}[\\{normal}]+\|q\L\|z)\V%
\30(\\{total\_shrink}[\\{fil}]\I0)\V(\\{total\_shrink}[\\{fill}]\I0)\V(\\{total%
\_shrink}[\\{filll}]\I0))$ \1\&{then}\6
\&{begin} \37$\\{free\_node}(\|b,\39\\{box\_node\_size})$;\5
$\|b\K\\{hpack}(\|p,\39\|z-\|q,\39\\{exactly})$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\|e\K0$;\6
\&{if} $\|w>\|z$ \1\&{then}\6
\&{begin} \37$\\{free\_node}(\|b,\39\\{box\_node\_size})$;\5
$\|b\K\\{hpack}(\|p,\39\|z,\39\\{exactly})$;\6
\&{end};\2\6
\&{end};\2\6
$\|w\K\\{width}(\|b)$;\6
\&{end}\par
\U section~1199.\fi

\M1202. We try first to center the display without regard to the existence of
the equation number. If that would make it too close (where ``too close''
means that the space between display and equation number is less than the
width of the equation number), we either center it in the remaining space
or move it as far from the equation number as possible. The latter alternative
is taken only if the display begins with glue, since we assume that the
user put glue there to control the spacing precisely.

\Y\P$\4\X1202:Determine the displacement, \|d, of the left edge of the
equation, with respect to the line size \|z, assuming that $\|l=\\{false}$\X\S$%
\6
$\|d\K\\{half}(\|z-\|w)$;\6
\&{if} $(\|e>0)\W(\|d<2\ast\|e)$ \1\&{then}\C{too close}\6
\&{begin} \37$\|d\K\\{half}(\|z-\|w-\|e)$;\6
\&{if} $\|p\I\\{null}$ \1\&{then}\6
\&{if} $\\{type}(\|p)=\\{glue\_node}$ \1\&{then}\5
$\|d\K0$;\2\2\6
\&{end}\2\par
\U section~1199.\fi

\M1203. If the equation number is set on a line by itself, either before or
after the formula, we append an infinite penalty so that no page break will
separate the display from its number; and we use the same size and
displacement for all three potential lines of the display, even though
`\.{\\parshape}' may specify them differently.

\Y\P$\4\X1203:Append the glue or equation number preceding the display\X\S$\6
$\\{tail\_append}(\\{new\_penalty}(\\{pre\_display\_penalty}))$;\6
\&{if} $(\|d+\|s\L\\{pre\_display\_size})\V\|l$ \1\&{then}\C{not enough
clearance}\6
\&{begin} \37$\\{g1}\K\\{above\_display\_skip\_code}$;\5
$\\{g2}\K\\{below\_display\_skip\_code}$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{g1}\K\\{above\_display\_short\_skip\_code}$;\5
$\\{g2}\K\\{below\_display\_short\_skip\_code}$;\6
\&{end};\2\6
\&{if} $\|l\W(\|e=0)$ \1\&{then}\C{it follows that $\\{type}(\|a)=\\{hlist%
\_node}$}\6
\&{begin} \37$\\{shift\_amount}(\|a)\K\|s$;\5
$\\{append\_to\_vlist}(\|a)$;\5
$\\{tail\_append}(\\{new\_penalty}(\\{inf\_penalty}))$;\6
\&{end}\6
\4\&{else} $\\{tail\_append}(\\{new\_param\_glue}(\\{g1}))$\2\par
\U section~1199.\fi

\M1204. \P$\X1204:Append the display and perhaps also the equation number\X\S$\6
\&{if} $\|e\I0$ \1\&{then}\6
\&{begin} \37$\|r\K\\{new\_kern}(\|z-\|w-\|e-\|d)$;\6
\&{if} $\|l$ \1\&{then}\6
\&{begin} \37$\\{link}(\|a)\K\|r$;\5
$\\{link}(\|r)\K\|b$;\5
$\|b\K\|a$;\5
$\|d\K0$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{link}(\|b)\K\|r$;\5
$\\{link}(\|r)\K\|a$;\6
\&{end};\2\6
$\|b\K\\{hpack}(\|b,\39\\{natural})$;\6
\&{end};\2\6
$\\{shift\_amount}(\|b)\K\|s+\|d$;\5
$\\{append\_to\_vlist}(\|b)$;\6
\&{if} $\|t\I\\{adjust\_head}$ \1\&{then}\6
\&{begin} \37$\\{link}(\\{tail})\K\\{link}(\\{adjust\_head})$;\5
$\\{tail}\K\|t$;\6
\&{end}\2\par
\U section~1199.\fi

\M1205. \P$\X1205:Append the glue or equation number following the display\X\S$%
\6
\&{if} $(\|a\I\\{null})\W(\|e=0)\W\R\|l$ \1\&{then}\6
\&{begin} \37$\\{tail\_append}(\\{new\_penalty}(\\{inf\_penalty}))$;\5
$\\{shift\_amount}(\|a)\K\|s+\|z-\\{width}(\|a)$;\5
$\\{append\_to\_vlist}(\|a)$;\5
$\\{tail\_append}(\\{new\_penalty}(\\{post\_display\_penalty}))$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{tail\_append}(\\{new\_penalty}(\\{post\_display%
\_penalty}))$;\5
$\\{tail\_append}(\\{new\_param\_glue}(\\{g2}))$;\6
\&{end}\2\par
\U section~1199.\fi

\M1206. When \.{\\halign} appears in a display, the alignment routines operate
essentially as they do in vertical mode. Then the following program is
activated, with \|p and \|q pointing to the beginning and end of the
resulting list, and with \|t the \\{prev\_depth} value.

\Y\P$\4\X1206:Finish an alignment in a display\X\S$\6
\&{begin} \37\\{do\_assignments};\6
\&{if} $\\{cur\_cmd}\I\\{math\_shift}$ \1\&{then}\5
\X1207:Pontificate about improper alignment in display\X\6
\4\&{else} \X1197:Check that another \.\$ follows\X;\2\6
\\{pop\_nest};\5
$\\{tail\_append}(\\{new\_penalty}(\\{pre\_display\_penalty}))$;\5
$\\{tail\_append}(\\{new\_param\_glue}(\\{above\_display\_skip\_code}))$;\5
$\\{link}(\\{tail})\K\|p$;\6
\&{if} $\|p\I\\{null}$ \1\&{then}\5
$\\{tail}\K\|q$;\2\6
$\\{tail\_append}(\\{new\_penalty}(\\{post\_display\_penalty}))$;\5
$\\{tail\_append}(\\{new\_param\_glue}(\\{below\_display\_skip\_code}))$;\5
$\\{prev\_depth}\K\|t$;\5
\\{resume\_after\_display};\6
\&{end}\par
\U section~812.\fi

\M1207. \P$\X1207:Pontificate about improper alignment in display\X\S$\6
\&{begin} \37$\\{print\_err}(\.{"Missing\ \$\$\ inserted"})$;\5
$\\{help2}(\.{"Displays\ can\ use\ special\ alignments\ (like\ \\eqalignno)"})$%
\6
$(\.{"only\ if\ nothing\ but\ the\ alignment\ itself\ is\ between\ \$\$%
\'s."})$;\5
\\{back\_error};\6
\&{end}\par
\U section~1206.\fi

\N1208.  \[49] Mode-independent processing.
The long \\{main\_control} procedure has now been fully specified, except for
certain activities that are independent of the current mode. These activities
do not change the current vlist or hlist or mlist; if they change anything,
it is the value of a parameter or the meaning of a control sequence.

Assignments to values in \\{eqtb} can be global or local. Furthermore, a
control sequence can be defined to be `\.{\\long}' or `\.{\\outer}', and
it might or might not be expanded. The prefixes `\.{\\global}', `\.{\\long}',
and `\.{\\outer}' can occur in any order. Therefore we assign binary numeric
codes, making it possible to accumulate the union of all specified prefixes
by adding the corresponding codes.  (\PASCAL's \&{set}  operations could also
have been used.)

\Y\P$\4\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}\S$\6
$\\{primitive}(\.{"long"},\39\\{prefix},\391)$;\5
$\\{primitive}(\.{"outer"},\39\\{prefix},\392)$;\5
$\\{primitive}(\.{"global"},\39\\{prefix},\394)$;\5
$\\{primitive}(\.{"def"},\39\\{def},\390)$;\5
$\\{primitive}(\.{"gdef"},\39\\{def},\391)$;\5
$\\{primitive}(\.{"edef"},\39\\{def},\392)$;\5
$\\{primitive}(\.{"xdef"},\39\\{def},\393)$;\par
\fi

\M1209. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{prefix}: \37\&{if} $\\{chr\_code}=1$ \1\&{then}\5
$\\{print\_esc}(\.{"long"})$\6
\4\&{else} \&{if} $\\{chr\_code}=2$ \1\&{then}\5
$\\{print\_esc}(\.{"outer"})$\6
\4\&{else} $\\{print\_esc}(\.{"global"})$;\2\2\6
\4\\{def}: \37\&{if} $\\{chr\_code}=0$ \1\&{then}\5
$\\{print\_esc}(\.{"def"})$\6
\4\&{else} \&{if} $\\{chr\_code}=1$ \1\&{then}\5
$\\{print\_esc}(\.{"gdef"})$\6
\4\&{else} \&{if} $\\{chr\_code}=2$ \1\&{then}\5
$\\{print\_esc}(\.{"edef"})$\6
\4\&{else} $\\{print\_esc}(\.{"xdef"})$;\2\2\2\par
\fi

\M1210. Every prefix, and every command code that might or might not be
prefixed,
calls the action procedure \\{prefixed\_command}. This routine accumulates
a sequence of prefixes until coming to a non-prefix, then it carries out
the command.

\Y\P$\4\X1210:Cases of \\{main\_control} that don't depend on \\{mode}\X\S$\6
\4$\\{any\_mode}(\\{toks\_register}),\39\\{any\_mode}(\\{assign\_toks}),\39%
\\{any\_mode}(\\{assign\_int}),\39\\{any\_mode}(\\{assign\_dimen}),\39\\{any%
\_mode}(\\{assign\_glue}),\39\\{any\_mode}(\\{assign\_mu\_glue}),\39\\{any%
\_mode}(\\{assign\_font\_dimen}),\39\\{any\_mode}(\\{assign\_font\_int}),\39%
\\{any\_mode}(\\{set\_aux}),\39\\{any\_mode}(\\{set\_prev\_graf}),\39\\{any%
\_mode}(\\{set\_page\_dimen}),\39\\{any\_mode}(\\{set\_page\_int}),\39\\{any%
\_mode}(\\{set\_box\_dimen}),\39\\{any\_mode}(\\{set\_shape}),\39\\{any\_mode}(%
\\{def\_code}),\39\\{any\_mode}(\\{def\_family}),\39\\{any\_mode}(\\{set%
\_font}),\39\\{any\_mode}(\\{def\_font}),\39\\{any\_mode}(\\{register}),\39%
\\{any\_mode}(\\{advance}),\39\\{any\_mode}(\\{multiply}),\39\\{any\_mode}(%
\\{divide}),\39\\{any\_mode}(\\{prefix}),\39\\{any\_mode}(\\{let}),\39\\{any%
\_mode}(\\{shorthand\_def}),\39\\{any\_mode}(\\{read\_to\_cs}),\39\\{any%
\_mode}(\\{def}),\39\\{any\_mode}(\\{set\_box}),\39\\{any\_mode}(\\{hyph%
\_data}),\39\\{any\_mode}(\\{set\_interaction})$: \37\\{prefixed\_command};\par
\A sections~1268, 1271, 1274, 1276, 1285, and~1290.
\U section~1045.\fi

\M1211. If the user says, e.g., `\.{\\global\\global}', the redundancy is
silently accepted.

\Y\P$\4\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\hbox{\4}\X1215:Declare subprocedures for \\{prefixed\_command}\X\hbox{}\6
\4\&{procedure}\1\  \37\\{prefixed\_command};\6
\4\&{label} \37$\\{done},\39\\{exit}$;\6
\4\&{var} \37\|a: \37\\{small\_number};\C{accumulated prefix codes so far}\6
\|f: \37\\{internal\_font\_number};\C{identifies a font}\6
\|j: \37\\{halfword};\C{index into a \.{\\parshape} specification}\6
\|k: \37$0\to\\{font\_mem\_size}$;\C{index into \\{font\_info}}\6
$\|p,\39\|q$: \37\\{pointer};\C{for temporary short-term use}\6
\|n: \37\\{integer};\C{ditto}\6
\|e: \37\\{boolean};\C{should a definition be expanded? or was \.{\\let} not
done?}\2\6
\&{begin} \37$\|a\K0$;\6
\&{while} $\\{cur\_cmd}=\\{prefix}$ \1\&{do}\6
\&{begin} \37\&{if} $\R\\{odd}(\|a\mathbin{\&{div}}\\{cur\_chr})$ \1\&{then}\5
$\|a\K\|a+\\{cur\_chr}$;\2\6
\X404:Get the next non-blank non-relax non-call token\X;\6
\&{if} $\\{cur\_cmd}\L\\{max\_non\_prefixed\_command}$ \1\&{then}\5
\X1212:Discard erroneous prefixes and \&{return}\X;\2\6
\&{end};\2\6
\X1213:Discard the prefixes \.{\\long} and \.{\\outer} if they are irrelevant%
\X;\6
\X1214:Adjust \(f)for the setting of \.{\\globaldefs}\X;\6
\&{case} $\\{cur\_cmd}$ \1\&{of}\6
\hbox{\4}\X1217:Assignments\X\6
\4\&{othercases} \37$\\{confusion}(\.{"prefix"})$\2\6
\&{endcases};\6
\4\\{done}: \37\X1269:Insert a token saved by \.{\\afterassignment}, if any\X;\6
\4\\{exit}: \37\&{end};\par
\fi

\M1212. \P$\X1212:Discard erroneous prefixes and \&{return}\X\S$\6
\&{begin} \37$\\{print\_err}(\.{"You\ can\'t\ use\ a\ prefix\ with\ \`"})$;\5
$\\{print\_cmd\_chr}(\\{cur\_cmd},\39\\{cur\_chr})$;\5
$\\{print\_char}(\.{"\'"})$;\5
$\\{help1}(\.{"I\'ll\ pretend\ you\ didn\'t\ say\ \\long\ or\ \\outer\ or\ %
\\global."})$;\5
\\{back\_error};\5
\&{return};\6
\&{end}\par
\U section~1211.\fi

\M1213. \P$\X1213:Discard the prefixes \.{\\long} and \.{\\outer} if they are
irrelevant\X\S$\6
\&{if} $(\\{cur\_cmd}\I\\{def})\W(\|a\mathbin{\&{mod}}4\I0)$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"You\ can\'t\ use\ \`"})$;\5
$\\{print\_esc}(\.{"long"})$;\5
$\\{print}(\.{"\'\ or\ \`"})$;\5
$\\{print\_esc}(\.{"outer"})$;\5
$\\{print}(\.{"\'\ with\ \`"})$;\5
$\\{print\_cmd\_chr}(\\{cur\_cmd},\39\\{cur\_chr})$;\5
$\\{print\_char}(\.{"\'"})$;\5
$\\{help1}(\.{"I\'ll\ pretend\ you\ didn\'t\ say\ \\long\ or\ \\outer\
here."})$;\5
\\{error};\6
\&{end}\2\par
\U section~1211.\fi

\M1214. The previous routine does not have to adjust \|a so that $\|a\mathbin{%
\&{mod}}4=0$,
since the following routines test for the \.{\\global} prefix as follows.

\Y\P\D \37$\\{global}\S(\|a\G4)$\par
\P\D \37$\\{define}(\#)\S$\1\6
\&{if} $\\{global}$ \1\&{then}\5
$\\{geq\_define}(\#)$\ \&{else} $\\{eq\_define}(\#)$\2\2\par
\P\D \37$\\{word\_define}(\#)\S$\1\6
\&{if} $\\{global}$ \1\&{then}\5
$\\{geq\_word\_define}(\#)$\ \&{else} $\\{eq\_word\_define}(\#)$\2\2\par
\Y\P$\4\X1214:Adjust \(f)for the setting of \.{\\globaldefs}\X\S$\6
\&{if} $\\{global\_defs}\I0$ \1\&{then}\6
\&{if} $\\{global\_defs}<0$ \1\&{then}\6
\&{begin} \37\&{if} $\\{global}$ \1\&{then}\5
$\|a\K\|a-4$;\2\6
\&{end}\6
\4\&{else} \&{begin} \37\&{if} $\R\\{global}$ \1\&{then}\5
$\|a\K\|a+4$;\2\6
\&{end}\2\2\par
\U section~1211.\fi

\M1215. When a control sequence is to be defined, by \.{\\def} or \.{\\let} or
something similar, the \\{get\_r\_token} routine will substitute a special
control sequence for a token that is not redefinable.

\Y\P$\4\X1215:Declare subprocedures for \\{prefixed\_command}\X\S$\6
\4\&{procedure}\1\  \37\\{get\_r\_token};\6
\4\&{label} \37\\{restart};\2\6
\&{begin} \37\\{restart}: \37\1\&{repeat} \37\\{get\_token};\6
\4\&{until}\5
$\\{cur\_tok}\I\\{space\_token}$;\2\6
\&{if} $(\\{cur\_cs}=0)\V(\\{cur\_cs}>\\{frozen\_control\_sequence})$ \1%
\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Missing\ control\ sequence\ inserted"})$;\5
$\\{help5}(\.{"Please\ don\'t\ say\ \`\\def\ cs\{...\}\',\ say\ \`\\def\\cs%
\{...\}\'."})$\6
$(\.{"I\'ve\ inserted\ an\ inaccessible\ control\ sequence\ so\ that\ your"})$\6
$(\.{"definition\ will\ be\ completed\ without\ mixing\ me\ up\ too\ badly."})$%
\6
$(\.{"You\ can\ recover\ graciously\ from\ this\ error,\ if\ you\'re"})$\6
$(\.{"careful;\ see\ exercise\ 27.2\ in\ The\ TeXbook."})$;\6
\&{if} $\\{cur\_cs}=0$ \1\&{then}\5
\\{back\_input};\2\6
$\\{cur\_tok}\K\\{cs\_token\_flag}+\\{frozen\_protection}$;\5
\\{ins\_error};\5
\&{goto} \37\\{restart};\6
\&{end};\2\6
\&{end};\par
\A sections~1229, 1236, 1243, 1244, 1245, 1246, 1247, 1257, and~1265.
\U section~1211.\fi

\M1216. \P$\X164:Initialize table entries (done by \.{INITEX} only)\X%
\mathrel{+}\S$\6
$\\{text}(\\{frozen\_protection})\K\.{"inaccessible"}$;\par
\fi

\M1217. Here's an example of the way many of the following routines operate.
(Unfortunately, they aren't all as simple as this.)

\Y\P$\4\X1217:Assignments\X\S$\6
\4\\{set\_font}: \37$\\{define}(\\{cur\_font\_loc},\39\\{data},\39\\{cur%
\_chr})$;\par
\A sections~1218, 1221, 1224, 1225, 1226, 1228, 1232, 1234, 1235, 1241, 1242,
1248, 1252, 1253, 1256, and~1264.
\U section~1211.\fi

\M1218. When a \\{def} command has been scanned,
\\{cur\_chr} is odd if the definition is supposed to be global, and
$\\{cur\_chr}\G2$ if the definition is supposed to be expanded.

\Y\P$\4\X1217:Assignments\X\mathrel{+}\S$\6
\4\\{def}: \37\&{begin} \37\&{if} $\\{odd}(\\{cur\_chr})\W\R\\{global}\W(%
\\{global\_defs}\G0)$ \1\&{then}\5
$\|a\K\|a+4$;\2\6
$\|e\K(\\{cur\_chr}\G2)$;\5
\\{get\_r\_token};\5
$\|p\K\\{cur\_cs}$;\5
$\|q\K\\{scan\_toks}(\\{true},\39\|e)$;\5
$\\{define}(\|p,\39\\{call}+(\|a\mathbin{\&{mod}}4),\39\\{def\_ref})$;\6
\&{end};\par
\fi

\M1219. Both \.{\\let} and \.{\\futurelet} share the command code \\{let}.

\Y\P$\4\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}\S$\6
$\\{primitive}(\.{"let"},\39\\{let},\39\\{normal})$;\6
$\\{primitive}(\.{"futurelet"},\39\\{let},\39\\{normal}+1)$;\par
\fi

\M1220. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{let}: \37\&{if} $\\{chr\_code}\I\\{normal}$ \1\&{then}\5
$\\{print\_esc}(\.{"futurelet"})$\ \&{else} $\\{print\_esc}(\.{"let"})$;\2\par
\fi

\M1221. \P$\X1217:Assignments\X\mathrel{+}\S$\6
\4\\{let}: \37\&{begin} \37$\|n\K\\{cur\_chr}$;\5
\\{get\_r\_token};\5
$\|p\K\\{cur\_cs}$;\6
\&{if} $\|n=\\{normal}$ \1\&{then}\6
\&{begin} \37\1\&{repeat} \37\\{get\_token};\6
\4\&{until}\5
$\\{cur\_cmd}\I\\{spacer}$;\2\6
\&{if} $\\{cur\_tok}=\\{other\_token}+\.{"="}$ \1\&{then}\6
\&{begin} \37\\{get\_token};\6
\&{if} $\\{cur\_cmd}=\\{spacer}$ \1\&{then}\5
\\{get\_token};\2\6
\&{end};\2\6
\&{end}\6
\4\&{else} \&{begin} \37\\{get\_token};\5
$\|q\K\\{cur\_tok}$;\5
\\{get\_token};\5
\\{back\_input};\5
$\\{cur\_tok}\K\|q$;\5
\\{back\_input};\C{look ahead, then back up}\6
\&{end};\C{note that \\{back\_input} doesn't affect \\{cur\_cmd}, \\{cur\_chr}}%
\2\6
\&{if} $\\{cur\_cmd}\G\\{call}$ \1\&{then}\5
$\\{add\_token\_ref}(\\{cur\_chr})$;\2\6
$\\{define}(\|p,\39\\{cur\_cmd},\39\\{cur\_chr})$;\6
\&{end};\par
\fi

\M1222. A \.{\\chardef} creates a control sequence whose \\{cmd} is \\{char%
\_given};
a \.{\\mathchardef} creates a control sequence whose \\{cmd} is \\{math%
\_given};
and the corresponding \\{chr} is the character code or math code. A \.{%
\\countdef}
or \.{\\dimendef} or \.{\\skipdef} or \.{\\muskipdef} creates a control
sequence whose \\{cmd} is \\{assign\_int} or \dots\ or \\{assign\_mu\_glue},
and the
corresponding \\{chr} is the \\{eqtb} location of the internal register in
question.

\Y\P\D \37$\\{char\_def\_code}=0$\C{\\{shorthand\_def} for \.{\\chardef}}\par
\P\D \37$\\{math\_char\_def\_code}=1$\C{\\{shorthand\_def} for \.{%
\\mathchardef}}\par
\P\D \37$\\{count\_def\_code}=2$\C{\\{shorthand\_def} for \.{\\countdef}}\par
\P\D \37$\\{dimen\_def\_code}=3$\C{\\{shorthand\_def} for \.{\\dimendef}}\par
\P\D \37$\\{skip\_def\_code}=4$\C{\\{shorthand\_def} for \.{\\skipdef}}\par
\P\D \37$\\{mu\_skip\_def\_code}=5$\C{\\{shorthand\_def} for \.{\\muskipdef}}%
\par
\P\D \37$\\{toks\_def\_code}=6$\C{\\{shorthand\_def} for \.{\\toksdef}}\par
\Y\P$\4\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}\S$\6
$\\{primitive}(\.{"chardef"},\39\\{shorthand\_def},\39\\{char\_def\_code})$;\6
$\\{primitive}(\.{"mathchardef"},\39\\{shorthand\_def},\39\\{math\_char\_def%
\_code})$;\6
$\\{primitive}(\.{"countdef"},\39\\{shorthand\_def},\39\\{count\_def\_code})$;\6
$\\{primitive}(\.{"dimendef"},\39\\{shorthand\_def},\39\\{dimen\_def\_code})$;\6
$\\{primitive}(\.{"skipdef"},\39\\{shorthand\_def},\39\\{skip\_def\_code})$;\6
$\\{primitive}(\.{"muskipdef"},\39\\{shorthand\_def},\39\\{mu\_skip\_def%
\_code})$;\6
$\\{primitive}(\.{"toksdef"},\39\\{shorthand\_def},\39\\{toks\_def\_code})$;\par
\fi

\M1223. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{shorthand\_def}: \37\&{case} $\\{chr\_code}$ \1\&{of}\6
\4\\{char\_def\_code}: \37$\\{print\_esc}(\.{"chardef"})$;\6
\4\\{math\_char\_def\_code}: \37$\\{print\_esc}(\.{"mathchardef"})$;\6
\4\\{count\_def\_code}: \37$\\{print\_esc}(\.{"countdef"})$;\6
\4\\{dimen\_def\_code}: \37$\\{print\_esc}(\.{"dimendef"})$;\6
\4\\{skip\_def\_code}: \37$\\{print\_esc}(\.{"skipdef"})$;\6
\4\\{mu\_skip\_def\_code}: \37$\\{print\_esc}(\.{"muskipdef"})$;\6
\4\&{othercases} \37$\\{print\_esc}(\.{"toksdef"})$\2\6
\&{endcases};\6
\4\\{char\_given}: \37\&{begin} \37$\\{print\_esc}(\.{"char"})$;\5
$\\{print\_hex}(\\{chr\_code})$;\6
\&{end};\6
\4\\{math\_given}: \37\&{begin} \37$\\{print\_esc}(\.{"mathchar"})$;\5
$\\{print\_hex}(\\{chr\_code})$;\6
\&{end};\par
\fi

\M1224. We temporarily define \|p to be \\{relax}, so that an occurrence of \|p
while scanning the definition will simply stop the scanning instead of
producing an ``undefined control sequence'' error or expanding the
previous meaning.  This allows, for instance, `\.{\\chardef\\foo=123\\foo}'.

\Y\P$\4\X1217:Assignments\X\mathrel{+}\S$\6
\4\\{shorthand\_def}: \37\&{begin} \37$\|n\K\\{cur\_chr}$;\5
\\{get\_r\_token};\5
$\|p\K\\{cur\_cs}$;\5
$\\{define}(\|p,\39\\{relax},\39256)$;\5
\\{scan\_optional\_equals};\6
\&{case} $\|n$ \1\&{of}\6
\4\\{char\_def\_code}: \37\&{begin} \37\\{scan\_char\_num};\5
$\\{define}(\|p,\39\\{char\_given},\39\\{cur\_val})$;\6
\&{end};\6
\4\\{math\_char\_def\_code}: \37\&{begin} \37\\{scan\_fifteen\_bit\_int};\5
$\\{define}(\|p,\39\\{math\_given},\39\\{cur\_val})$;\6
\&{end};\6
\4\&{othercases} \37\&{begin} \37\\{scan\_eight\_bit\_int};\6
\&{case} $\|n$ \1\&{of}\6
\4\\{count\_def\_code}: \37$\\{define}(\|p,\39\\{assign\_int},\39\\{count%
\_base}+\\{cur\_val})$;\6
\4\\{dimen\_def\_code}: \37$\\{define}(\|p,\39\\{assign\_dimen},\39\\{scaled%
\_base}+\\{cur\_val})$;\6
\4\\{skip\_def\_code}: \37$\\{define}(\|p,\39\\{assign\_glue},\39\\{skip%
\_base}+\\{cur\_val})$;\6
\4\\{mu\_skip\_def\_code}: \37$\\{define}(\|p,\39\\{assign\_mu\_glue},\39\\{mu%
\_skip\_base}+\\{cur\_val})$;\6
\4\\{toks\_def\_code}: \37$\\{define}(\|p,\39\\{assign\_toks},\39\\{toks%
\_base}+\\{cur\_val})$;\2\6
\&{end};\C{there are no other cases}\6
\&{end}\2\6
\&{endcases};\6
\&{end};\par
\fi

\M1225. \P$\X1217:Assignments\X\mathrel{+}\S$\6
\4\\{read\_to\_cs}: \37\&{begin} \37\\{scan\_int};\5
$\|n\K\\{cur\_val}$;\6
\&{if} $\R\\{scan\_keyword}(\.{"to"})$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Missing\ \`to\'\ inserted"})$;\5
$\\{help2}(\.{"You\ should\ have\ said\ \`\\read<number>\ to\ \\cs\'."})$\6
$(\.{"I\'m\ going\ to\ look\ for\ the\ \\cs\ now."})$;\5
\\{error};\6
\&{end};\2\6
\\{get\_r\_token};\5
$\|p\K\\{cur\_cs}$;\5
$\\{read\_toks}(\|n,\39\|p)$;\5
$\\{define}(\|p,\39\\{call},\39\\{cur\_val})$;\6
\&{end};\par
\fi

\M1226. The token-list parameters, \.{\\output} and \.{\\everypar}, etc.,
receive
their values in the following way. (For safety's sake, we place an
enclosing pair of braces around an \.{\\output} list.)

\Y\P$\4\X1217:Assignments\X\mathrel{+}\S$\6
\4$\\{toks\_register},\39\\{assign\_toks}$: \37\&{begin} \37$\|q\K\\{cur\_cs}$;%
\6
\&{if} $\\{cur\_cmd}=\\{toks\_register}$ \1\&{then}\6
\&{begin} \37\\{scan\_eight\_bit\_int};\5
$\|p\K\\{toks\_base}+\\{cur\_val}$;\6
\&{end}\6
\4\&{else} $\|p\K\\{cur\_chr}$;\C{$\|p=\\{every\_par\_loc}$ or \\{output%
\_routine\_loc} or \dots}\2\6
\\{scan\_optional\_equals};\5
\X404:Get the next non-blank non-relax non-call token\X;\6
\&{if} $\\{cur\_cmd}\I\\{left\_brace}$ \1\&{then}\5
\X1227:If the right-hand side is a token parameter or token register, finish
the assignment and \&{goto} \\{done}\X;\2\6
\\{back\_input};\5
$\\{cur\_cs}\K\|q$;\5
$\|q\K\\{scan\_toks}(\\{false},\39\\{false})$;\6
\&{if} $\\{link}(\\{def\_ref})=\\{null}$ \1\&{then}\C{empty list: revert to the
default}\6
\&{begin} \37$\\{define}(\|p,\39\\{undefined\_cs},\39\\{null})$;\5
$\\{free\_avail}(\\{def\_ref})$;\6
\&{end}\6
\4\&{else} \&{begin} \37\&{if} $\|p=\\{output\_routine\_loc}$ \1\&{then}%
\C{enclose in curlies}\6
\&{begin} \37$\\{link}(\|q)\K\\{get\_avail}$;\5
$\|q\K\\{link}(\|q)$;\5
$\\{info}(\|q)\K\\{right\_brace\_token}+\.{"\}"}$;\5
$\|q\K\\{get\_avail}$;\5
$\\{info}(\|q)\K\\{left\_brace\_token}+\.{"\{"}$;\5
$\\{link}(\|q)\K\\{link}(\\{def\_ref})$;\5
$\\{link}(\\{def\_ref})\K\|q$;\6
\&{end};\2\6
$\\{define}(\|p,\39\\{call},\39\\{def\_ref})$;\6
\&{end};\2\6
\&{end};\par
\fi

\M1227. \P$\X1227:If the right-hand side is a token parameter or token
register, finish the assignment and \&{goto} \\{done}\X\S$\6
\&{begin} \37\&{if} $\\{cur\_cmd}=\\{toks\_register}$ \1\&{then}\6
\&{begin} \37\\{scan\_eight\_bit\_int};\5
$\\{cur\_cmd}\K\\{assign\_toks}$;\5
$\\{cur\_chr}\K\\{toks\_base}+\\{cur\_val}$;\6
\&{end};\2\6
\&{if} $\\{cur\_cmd}=\\{assign\_toks}$ \1\&{then}\6
\&{begin} \37$\|q\K\\{equiv}(\\{cur\_chr})$;\6
\&{if} $\|q=\\{null}$ \1\&{then}\5
$\\{define}(\|p,\39\\{undefined\_cs},\39\\{null})$\6
\4\&{else} \&{begin} \37$\\{add\_token\_ref}(\|q)$;\5
$\\{define}(\|p,\39\\{call},\39\|q)$;\6
\&{end};\2\6
\&{goto} \37\\{done};\6
\&{end};\2\6
\&{end}\par
\U section~1226.\fi

\M1228. Similar routines are used to assign values to the numeric parameters.

\Y\P$\4\X1217:Assignments\X\mathrel{+}\S$\6
\4\\{assign\_int}: \37\&{begin} \37$\|p\K\\{cur\_chr}$;\5
\\{scan\_optional\_equals};\5
\\{scan\_int};\5
$\\{word\_define}(\|p,\39\\{cur\_val})$;\6
\&{end};\6
\4\\{assign\_dimen}: \37\&{begin} \37$\|p\K\\{cur\_chr}$;\5
\\{scan\_optional\_equals};\5
\\{scan\_normal\_dimen};\5
$\\{word\_define}(\|p,\39\\{cur\_val})$;\6
\&{end};\6
\4$\\{assign\_glue},\39\\{assign\_mu\_glue}$: \37\&{begin} \37$\|p\K\\{cur%
\_chr}$;\5
$\|n\K\\{cur\_cmd}$;\5
\\{scan\_optional\_equals};\6
\&{if} $\|n=\\{assign\_mu\_glue}$ \1\&{then}\5
$\\{scan\_glue}(\\{mu\_val})$\ \&{else} $\\{scan\_glue}(\\{glue\_val})$;\2\6
\\{trap\_zero\_glue};\5
$\\{define}(\|p,\39\\{glue\_ref},\39\\{cur\_val})$;\6
\&{end};\par
\fi

\M1229. When a glue register or parameter becomes zero, it will always point to
\\{zero\_glue} because of the following procedure.

\Y\P$\4\X1215:Declare subprocedures for \\{prefixed\_command}\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{trap\_zero\_glue};\2\6
\&{begin} \37\&{if} $(\\{width}(\\{cur\_val})=0)\W(\\{stretch}(\\{cur\_val})=0)%
\W(\\{shrink}(\\{cur\_val})=0)$ \1\&{then}\6
\&{begin} \37$\\{add\_glue\_ref}(\\{zero\_glue})$;\5
$\\{delete\_glue\_ref}(\\{cur\_val})$;\5
$\\{cur\_val}\K\\{zero\_glue}$;\6
\&{end};\2\6
\&{end};\par
\fi

\M1230. The various character code tables are changed by the \\{def\_code}
commands,
and the font families are declared by \\{def\_family}.

\Y\P$\4\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}\S$\6
$\\{primitive}(\.{"catcode"},\39\\{def\_code},\39\\{cat\_code\_base})$;\5
$\\{primitive}(\.{"mathcode"},\39\\{def\_code},\39\\{math\_code\_base})$;\5
$\\{primitive}(\.{"lccode"},\39\\{def\_code},\39\\{lc\_code\_base})$;\5
$\\{primitive}(\.{"uccode"},\39\\{def\_code},\39\\{uc\_code\_base})$;\5
$\\{primitive}(\.{"sfcode"},\39\\{def\_code},\39\\{sf\_code\_base})$;\5
$\\{primitive}(\.{"delcode"},\39\\{def\_code},\39\\{del\_code\_base})$;\5
$\\{primitive}(\.{"textfont"},\39\\{def\_family},\39\\{math\_font\_base})$;\5
$\\{primitive}(\.{"scriptfont"},\39\\{def\_family},\39\\{math\_font\_base}+%
\\{script\_size})$;\5
$\\{primitive}(\.{"scriptscriptfont"},\39\\{def\_family},\39\\{math\_font%
\_base}+\\{script\_script\_size})$;\par
\fi

\M1231. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{def\_code}: \37\&{if} $\\{chr\_code}=\\{cat\_code\_base}$ \1\&{then}\5
$\\{print\_esc}(\.{"catcode"})$\6
\4\&{else} \&{if} $\\{chr\_code}=\\{math\_code\_base}$ \1\&{then}\5
$\\{print\_esc}(\.{"mathcode"})$\6
\4\&{else} \&{if} $\\{chr\_code}=\\{lc\_code\_base}$ \1\&{then}\5
$\\{print\_esc}(\.{"lccode"})$\6
\4\&{else} \&{if} $\\{chr\_code}=\\{uc\_code\_base}$ \1\&{then}\5
$\\{print\_esc}(\.{"uccode"})$\6
\4\&{else} \&{if} $\\{chr\_code}=\\{sf\_code\_base}$ \1\&{then}\5
$\\{print\_esc}(\.{"sfcode"})$\6
\4\&{else} $\\{print\_esc}(\.{"delcode"})$;\2\2\2\2\2\6
\4\\{def\_family}: \37$\\{print\_size}(\\{chr\_code}-\\{math\_font\_base})$;\par
\fi

\M1232. The different types of code values have different legal ranges; the
following program is careful to check each case properly.

\Y\P$\4\X1217:Assignments\X\mathrel{+}\S$\6
\4\\{def\_code}: \37\&{begin} \37\X1233:Let \|n be the largest legal code
value, based on \\{cur\_chr}\X;\6
$\|p\K\\{cur\_chr}$;\5
\\{scan\_seven\_bit\_int};\5
$\|p\K\|p+\\{cur\_val}$;\5
\\{scan\_optional\_equals};\5
\\{scan\_int};\6
\&{if} $((\\{cur\_val}<0)\W(\|p<\\{del\_code\_base}))\V(\\{cur\_val}>\|n)$ \1%
\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Invalid\ code\ ("})$;\5
$\\{print\_int}(\\{cur\_val})$;\6
\&{if} $\|p<\\{del\_code\_base}$ \1\&{then}\5
$\\{print}(\.{"),\ should\ be\ in\ the\ range\ 0.."})$\6
\4\&{else} $\\{print}(\.{"),\ should\ be\ at\ most\ "})$;\2\6
$\\{print\_int}(\|n)$;\5
$\\{help1}(\.{"I\'m\ going\ to\ use\ 0\ instead\ of\ that\ illegal\ code\
value."})$;\6
\\{error};\5
$\\{cur\_val}\K0$;\6
\&{end};\2\6
\&{if} $\|p<\\{math\_code\_base}$ \1\&{then}\5
$\\{define}(\|p,\39\\{data},\39\\{cur\_val})$\6
\4\&{else} \&{if} $\|p<\\{del\_code\_base}$ \1\&{then}\5
$\\{define}(\|p,\39\\{data},\39\\{hi}(\\{cur\_val}))$\6
\4\&{else} $\\{word\_define}(\|p,\39\\{cur\_val})$;\2\2\6
\&{end};\par
\fi

\M1233. \P$\X1233:Let \|n be the largest legal code value, based on \\{cur%
\_chr}\X\S$\6
\&{if} $\\{cur\_chr}=\\{cat\_code\_base}$ \1\&{then}\5
$\|n\K\\{max\_char\_code}$\6
\4\&{else} \&{if} $\\{cur\_chr}=\\{math\_code\_base}$ \1\&{then}\5
$\|n\K\O{100000}$\6
\4\&{else} \&{if} $\\{cur\_chr}=\\{sf\_code\_base}$ \1\&{then}\5
$\|n\K\O{77777}$\6
\4\&{else} \&{if} $\\{cur\_chr}=\\{del\_code\_base}$ \1\&{then}\5
$\|n\K\O{77777777}$\6
\4\&{else} $\|n\K127$\2\2\2\2\par
\U section~1232.\fi

\M1234. \P$\X1217:Assignments\X\mathrel{+}\S$\6
\4\\{def\_family}: \37\&{begin} \37$\|p\K\\{cur\_chr}$;\5
\\{scan\_four\_bit\_int};\5
$\|p\K\|p+\\{cur\_val}$;\5
\\{scan\_optional\_equals};\5
\\{scan\_font\_ident};\5
$\\{define}(\|p,\39\\{data},\39\\{cur\_val})$;\6
\&{end};\par
\fi

\M1235. Next we consider changes to \TeX's numeric registers.

\Y\P$\4\X1217:Assignments\X\mathrel{+}\S$\6
\4$\\{register},\39\\{advance},\39\\{multiply},\39\\{divide}$: \37$\\{do%
\_register\_command}(\|a)$;\par
\fi

\M1236. We use the fact that $\\{register}<\\{advance}<\\{multiply}<%
\\{divide}$.

\Y\P$\4\X1215:Declare subprocedures for \\{prefixed\_command}\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{do\_register\_command}(\|a:\\{small\_number})$;\6
\4\&{label} \37$\\{found},\39\\{exit}$;\6
\4\&{var} \37$\|l,\39\|q,\39\|r,\39\|s$: \37\\{pointer};\C{for list
manipulation}\6
\|p: \37$\\{int\_val}\to\\{mu\_val}$;\C{type of register involved}\2\6
\&{begin} \37$\|q\K\\{cur\_cmd}$;\5
\X1237:Compute the register location \|l and its type \|p; but \&{return} if
invalid\X;\6
\&{if} $\|q=\\{register}$ \1\&{then}\5
\\{scan\_optional\_equals}\6
\4\&{else} \&{if} $\\{scan\_keyword}(\.{"by"})$ \1\&{then}\5
\\{do\_nothing};\C{optional `\.{by}'}\2\2\6
$\\{arith\_error}\K\\{false}$;\6
\&{if} $\|q<\\{multiply}$ \1\&{then}\5
\X1238:Compute result of \\{register} or \\{advance}, put it in \\{cur\_val}\X\6
\4\&{else} \X1240:Compute result of \\{multiply} or \\{divide}, put it in %
\\{cur\_val}\X;\2\6
\&{if} $\\{arith\_error}$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Arithmetic\ overflow"})$;\5
$\\{help2}(\.{"I\ can\'t\ carry\ out\ that\ multiplication\ or\ division,"})$\6
$(\.{"since\ the\ result\ is\ out\ of\ range."})$;\5
\\{error};\5
\&{return};\6
\&{end};\2\6
\&{if} $\|p<\\{glue\_val}$ \1\&{then}\5
$\\{word\_define}(\|l,\39\\{cur\_val})$\6
\4\&{else} \&{begin} \37\\{trap\_zero\_glue};\5
$\\{define}(\|l,\39\\{glue\_ref},\39\\{cur\_val})$;\6
\&{end};\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M1237. Here we use the fact that the consecutive codes $\\{int\_val}\to.\\{mu%
\_val}$ and
$\\{assign\_int}\to\\{assign\_mu\_glue}$ correspond to each other nicely.

\Y\P$\4\X1237:Compute the register location \|l and its type \|p; but %
\&{return} if invalid\X\S$\6
\&{begin} \37\&{if} $\|q\I\\{register}$ \1\&{then}\6
\&{begin} \37\\{get\_x\_token};\6
\&{if} $(\\{cur\_cmd}\G\\{assign\_int})\W(\\{cur\_cmd}\L\\{assign\_mu\_glue})$ %
\1\&{then}\6
\&{begin} \37$\|l\K\\{cur\_chr}$;\5
$\|p\K\\{cur\_cmd}-\\{assign\_int}$;\5
\&{goto} \37\\{found};\6
\&{end};\2\6
\&{if} $\\{cur\_cmd}\I\\{register}$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"You\ can\'t\ use\ \`"})$;\5
$\\{print\_cmd\_chr}(\\{cur\_cmd},\39\\{cur\_chr})$;\5
$\\{print}(\.{"\'\ after\ "})$;\5
$\\{print\_cmd\_chr}(\|q,\390)$;\5
$\\{help1}(\.{"I\'m\ forgetting\ what\ you\ said\ and\ not\ changing\
anything."})$;\5
\\{error};\5
\&{return};\6
\&{end};\2\6
\&{end};\2\6
$\|p\K\\{cur\_chr}$;\5
\\{scan\_eight\_bit\_int};\6
\&{case} $\|p$ \1\&{of}\6
\4\\{int\_val}: \37$\|l\K\\{cur\_val}+\\{count\_base}$;\6
\4\\{dimen\_val}: \37$\|l\K\\{cur\_val}+\\{scaled\_base}$;\6
\4\\{glue\_val}: \37$\|l\K\\{cur\_val}+\\{skip\_base}$;\6
\4\\{mu\_val}: \37$\|l\K\\{cur\_val}+\\{mu\_skip\_base}$;\2\6
\&{end};\C{there are no other cases}\6
\&{end};\6
\4\\{found}: \37\par
\U section~1236.\fi

\M1238. \P$\X1238:Compute result of \\{register} or \\{advance}, put it in %
\\{cur\_val}\X\S$\6
\&{if} $\|p<\\{glue\_val}$ \1\&{then}\6
\&{begin} \37\&{if} $\|p=\\{int\_val}$ \1\&{then}\5
\\{scan\_int}\ \&{else} \\{scan\_normal\_dimen};\2\6
\&{if} $\|q=\\{advance}$ \1\&{then}\5
$\\{cur\_val}\K\\{cur\_val}+\\{eqtb}[\|l].\\{int}$;\2\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{scan\_glue}(\|p)$;\6
\&{if} $\|q=\\{advance}$ \1\&{then}\5
\X1239:Compute the sum of two glue specs\X;\2\6
\&{end}\2\par
\U section~1236.\fi

\M1239. \P$\X1239:Compute the sum of two glue specs\X\S$\6
\&{begin} \37$\|q\K\\{new\_spec}(\\{cur\_val})$;\5
$\|r\K\\{equiv}(\|l)$;\5
$\\{delete\_glue\_ref}(\\{cur\_val})$;\5
$\\{width}(\|q)\K\\{width}(\|q)+\\{width}(\|r)$;\6
\&{if} $\\{stretch}(\|q)=0$ \1\&{then}\5
$\\{stretch\_order}(\|q)\K\\{normal}$;\2\6
\&{if} $\\{stretch\_order}(\|q)=\\{stretch\_order}(\|r)$ \1\&{then}\5
$\\{stretch}(\|q)\K\\{stretch}(\|q)+\\{stretch}(\|r)$\6
\4\&{else} \&{if} $(\\{stretch\_order}(\|q)<\\{stretch\_order}(\|r))\W(%
\\{stretch}(\|r)\I0)$ \1\&{then}\6
\&{begin} \37$\\{stretch}(\|q)\K\\{stretch}(\|r)$;\5
$\\{stretch\_order}(\|q)\K\\{stretch\_order}(\|r)$;\6
\&{end};\2\2\6
\&{if} $\\{shrink}(\|q)=0$ \1\&{then}\5
$\\{shrink\_order}(\|q)\K\\{normal}$;\2\6
\&{if} $\\{shrink\_order}(\|q)=\\{shrink\_order}(\|r)$ \1\&{then}\5
$\\{shrink}(\|q)\K\\{shrink}(\|q)+\\{shrink}(\|r)$\6
\4\&{else} \&{if} $(\\{shrink\_order}(\|q)<\\{shrink\_order}(\|r))\W(%
\\{shrink}(\|r)\I0)$ \1\&{then}\6
\&{begin} \37$\\{shrink}(\|q)\K\\{shrink}(\|r)$;\5
$\\{shrink\_order}(\|q)\K\\{shrink\_order}(\|r)$;\6
\&{end};\2\2\6
$\\{cur\_val}\K\|q$;\6
\&{end}\par
\U section~1238.\fi

\M1240. \P$\X1240:Compute result of \\{multiply} or \\{divide}, put it in %
\\{cur\_val}\X\S$\6
\&{begin} \37\\{scan\_int};\6
\&{if} $\|p<\\{glue\_val}$ \1\&{then}\6
\&{if} $\|q=\\{multiply}$ \1\&{then}\5
$\\{cur\_val}\K\\{nx\_plus\_y}(\\{eqtb}[\|l].\\{int},\39\\{cur\_val},\390)$\6
\4\&{else} $\\{cur\_val}\K\\{x\_over\_n}(\\{eqtb}[\|l].\\{int},\39\\{cur%
\_val})$\2\6
\4\&{else} \&{begin} \37$\|s\K\\{equiv}(\|l)$;\5
$\|r\K\\{new\_spec}(\|s)$;\6
\&{if} $\|q=\\{multiply}$ \1\&{then}\6
\&{begin} \37$\\{width}(\|r)\K\\{nx\_plus\_y}(\\{width}(\|s),\39\\{cur\_val},%
\390)$;\5
$\\{stretch}(\|r)\K\\{nx\_plus\_y}(\\{stretch}(\|s),\39\\{cur\_val},\390)$;\5
$\\{shrink}(\|r)\K\\{nx\_plus\_y}(\\{shrink}(\|s),\39\\{cur\_val},\390)$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{width}(\|r)\K\\{x\_over\_n}(\\{width}(\|s),\39%
\\{cur\_val})$;\5
$\\{stretch}(\|r)\K\\{x\_over\_n}(\\{stretch}(\|s),\39\\{cur\_val})$;\5
$\\{shrink}(\|r)\K\\{x\_over\_n}(\\{shrink}(\|s),\39\\{cur\_val})$;\6
\&{end};\2\6
$\\{cur\_val}\K\|r$;\6
\&{end};\2\6
\&{end}\par
\U section~1236.\fi

\M1241. The processing of boxes is somewhat different, because it may be
necessary
to scan and create an entire box before we actually change the value of the old
one.

\Y\P$\4\X1217:Assignments\X\mathrel{+}\S$\6
\4\\{set\_box}: \37\&{begin} \37\\{scan\_eight\_bit\_int};\6
\&{if} $\\{global}$ \1\&{then}\5
$\\{saved}(0)\K\\{box\_flag}+256+\\{cur\_val}$\6
\4\&{else} $\\{saved}(0)\K\\{box\_flag}+\\{cur\_val}$;\2\6
\\{scan\_optional\_equals};\5
\\{scan\_box};\6
\&{end};\par
\fi

\M1242. The \\{space\_factor} or \\{prev\_depth} settings are changed when a %
\\{set\_aux}
command is sensed. Similarly, \\{prev\_graf} is changed in the presence of
\\{set\_prev\_graf}, and \\{dead\_cycles} or \\{insert\_penalties} in the
presence of
\\{set\_page\_int}. These definitions are always global.

When some dimension of a box register is changed, the change isn't exactly
global; but \TeX\ does not look at the \.{\\global} switch.

\Y\P$\4\X1217:Assignments\X\mathrel{+}\S$\6
\4\\{set\_aux}: \37\\{alter\_aux};\6
\4\\{set\_prev\_graf}: \37\\{alter\_prev\_graf};\6
\4\\{set\_page\_dimen}: \37\\{alter\_page\_so\_far};\6
\4\\{set\_page\_int}: \37\\{alter\_integer};\6
\4\\{set\_box\_dimen}: \37\\{alter\_box\_dimen};\par
\fi

\M1243. \P$\X1215:Declare subprocedures for \\{prefixed\_command}\X\mathrel{+}%
\S$\6
\4\&{procedure}\1\  \37\\{alter\_aux};\6
\4\&{var} \37\|c: \37\\{halfword};\C{\\{hmode} or \\{vmode}}\2\6
\&{begin} \37\&{if} $\\{cur\_chr}\I\\{abs}(\\{mode})$ \1\&{then}\5
\\{report\_illegal\_case}\6
\4\&{else} \&{begin} \37$\|c\K\\{cur\_chr}$;\5
\\{scan\_optional\_equals};\6
\&{if} $\|c=\\{vmode}$ \1\&{then}\6
\&{begin} \37\\{scan\_normal\_dimen};\5
$\\{prev\_depth}\K\\{cur\_val}$;\6
\&{end}\6
\4\&{else} \&{begin} \37\\{scan\_int};\6
\&{if} $(\\{cur\_val}\L0)\V(\\{cur\_val}>32767)$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Bad\ space\ factor"})$;\5
$\\{help1}(\.{"I\ allow\ only\ values\ in\ the\ range\ 1..32767\ here."})$;\5
$\\{int\_error}(\\{cur\_val})$;\6
\&{end}\6
\4\&{else} $\\{space\_factor}\K\\{cur\_val}$;\2\6
\&{end};\2\6
\&{end};\2\6
\&{end};\par
\fi

\M1244. \P$\X1215:Declare subprocedures for \\{prefixed\_command}\X\mathrel{+}%
\S$\6
\4\&{procedure}\1\  \37\\{alter\_prev\_graf};\6
\4\&{var} \37\|p: \37$0\to\\{nest\_size}$;\C{index into \\{nest}}\2\6
\&{begin} \37$\\{nest}[\\{nest\_ptr}]\K\\{cur\_list}$;\5
$\|p\K\\{nest\_ptr}$;\6
\&{while} $\\{abs}(\\{nest}[\|p].\\{mode\_field})\I\\{vmode}$ \1\&{do}\5
$\\{decr}(\|p)$;\2\6
\\{scan\_optional\_equals};\5
\\{scan\_int};\6
\&{if} $\\{cur\_val}<0$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Bad\ "})$;\5
$\\{print\_esc}(\.{"prevgraf"})$;\5
$\\{help1}(\.{"I\ allow\ only\ nonnegative\ values\ here."})$;\5
$\\{int\_error}(\\{cur\_val})$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{nest}[\|p].\\{pg\_field}\K\\{cur\_val}$;\5
$\\{cur\_list}\K\\{nest}[\\{nest\_ptr}]$;\6
\&{end};\2\6
\&{end};\par
\fi

\M1245. \P$\X1215:Declare subprocedures for \\{prefixed\_command}\X\mathrel{+}%
\S$\6
\4\&{procedure}\1\  \37\\{alter\_page\_so\_far};\6
\4\&{var} \37\|c: \37$0\to7$;\C{index into \\{page\_so\_far}}\2\6
\&{begin} \37$\|c\K\\{cur\_chr}$;\5
\\{scan\_optional\_equals};\5
\\{scan\_normal\_dimen};\5
$\\{page\_so\_far}[\|c]\K\\{cur\_val}$;\6
\&{end};\par
\fi

\M1246. \P$\X1215:Declare subprocedures for \\{prefixed\_command}\X\mathrel{+}%
\S$\6
\4\&{procedure}\1\  \37\\{alter\_integer};\6
\4\&{var} \37\|c: \37$0\to1$;\C{0 for \.{\\deadcycles}, 1 for \.{%
\\insertpenalties}}\2\6
\&{begin} \37$\|c\K\\{cur\_chr}$;\5
\\{scan\_optional\_equals};\5
\\{scan\_int};\6
\&{if} $\|c=0$ \1\&{then}\5
$\\{dead\_cycles}\K\\{cur\_val}$\6
\4\&{else} $\\{insert\_penalties}\K\\{cur\_val}$;\2\6
\&{end};\par
\fi

\M1247. \P$\X1215:Declare subprocedures for \\{prefixed\_command}\X\mathrel{+}%
\S$\6
\4\&{procedure}\1\  \37\\{alter\_box\_dimen};\6
\4\&{var} \37\|c: \37\\{small\_number};\C{\\{width\_offset} or \\{height%
\_offset} or \\{depth\_offset}}\6
\|b: \37\\{eight\_bits};\C{box number}\2\6
\&{begin} \37$\|c\K\\{cur\_chr}$;\5
\\{scan\_eight\_bit\_int};\5
$\|b\K\\{cur\_val}$;\5
\\{scan\_optional\_equals};\5
\\{scan\_normal\_dimen};\6
\&{if} $\\{box}(\|b)\I\\{null}$ \1\&{then}\5
$\\{mem}[\\{box}(\|b)+\|c].\\{sc}\K\\{cur\_val}$;\2\6
\&{end};\par
\fi

\M1248. Paragraph shapes are set up in the obvious way.

\Y\P$\4\X1217:Assignments\X\mathrel{+}\S$\6
\4\\{set\_shape}: \37\&{begin} \37\\{scan\_optional\_equals};\5
\\{scan\_int};\5
$\|n\K\\{cur\_val}$;\6
\&{if} $\|n\L0$ \1\&{then}\5
$\|p\K\\{null}$\6
\4\&{else} \&{begin} \37$\|p\K\\{get\_node}(2\ast\|n+1)$;\5
$\\{info}(\|p)\K\|n$;\6
\&{for} $\|j\K1\mathrel{\&{to}}\|n$ \1\&{do}\6
\&{begin} \37\\{scan\_normal\_dimen};\5
$\\{mem}[\|p+2\ast\|j-1].\\{sc}\K\\{cur\_val}$;\C{indentation}\6
\\{scan\_normal\_dimen};\5
$\\{mem}[\|p+2\ast\|j].\\{sc}\K\\{cur\_val}$;\C{width}\6
\&{end};\2\6
\&{end};\2\6
$\\{define}(\\{par\_shape\_loc},\39\\{shape\_ref},\39\|p)$;\6
\&{end};\par
\fi

\M1249. Here's something that isn't quite so obvious. It guarantees that
$\\{info}(\\{par\_shape\_ptr})$ can hold any positive~\|n such $\\{get\_node}(2%
\ast\|n+1)$
doesn't overflow the memory capacity.

\Y\P$\4\X14:Check the ``constant'' values for consistency\X\mathrel{+}\S$\6
\&{if} $2\ast\\{max\_halfword}<\\{mem\_top}-\\{mem\_min}$ \1\&{then}\5
$\\{bad}\K41$;\2\par
\fi

\M1250. New hyphenation data is loaded by the \\{hyph\_data} command.

\Y\P$\4\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}\S$\6
$\\{primitive}(\.{"hyphenation"},\39\\{hyph\_data},\390)$;\5
$\\{primitive}(\.{"patterns"},\39\\{hyph\_data},\391)$;\par
\fi

\M1251. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{hyph\_data}: \37\&{if} $\\{chr\_code}=1$ \1\&{then}\5
$\\{print\_esc}(\.{"patterns"})$\6
\4\&{else} $\\{print\_esc}(\.{"hyphenation"})$;\2\par
\fi

\M1252. \P$\X1217:Assignments\X\mathrel{+}\S$\6
\4\\{hyph\_data}: \37\&{if} $\\{cur\_chr}=1$ \1\&{then}\6
\&{begin} \37\&{init} \37\\{new\_patterns};\5
\&{goto} \37\\{done};\ \&{tini}\6
$\\{print\_err}(\.{"Patterns\ can\ be\ loaded\ only\ by\ INITEX"})$;\5
\\{help0};\5
\\{error};\6
\1\&{repeat} \37\\{get\_token};\6
\4\&{until}\5
$\\{cur\_cmd}=\\{right\_brace}$;\C{flush the patterns}\2\6
\&{return};\6
\&{end}\6
\4\&{else} \&{begin} \37\\{new\_hyph\_exceptions};\5
\&{goto} \37\\{done};\6
\&{end};\2\par
\fi

\M1253. All of \TeX's parameters are kept in \\{eqtb} except the font
information,
the interaction mode, and the hyphenation tables; these are strictly global.

\Y\P$\4\X1217:Assignments\X\mathrel{+}\S$\6
\4\\{assign\_font\_dimen}: \37\&{begin} \37$\\{find\_font\_dimen}(\\{true})$;\5
$\|k\K\\{cur\_val}$;\5
\\{scan\_optional\_equals};\5
\\{scan\_normal\_dimen};\5
$\\{font\_info}[\|k].\\{sc}\K\\{cur\_val}$;\6
\&{end};\6
\4\\{assign\_font\_int}: \37\&{begin} \37$\|n\K\\{cur\_chr}$;\5
\\{scan\_font\_ident};\5
$\|f\K\\{cur\_val}$;\5
\\{scan\_optional\_equals};\5
\\{scan\_int};\6
\&{if} $\|n=0$ \1\&{then}\5
$\\{hyphen\_char}[\|f]\K\\{cur\_val}$\ \&{else} $\\{skew\_char}[\|f]\K\\{cur%
\_val}$;\2\6
\&{end};\par
\fi

\M1254. \P$\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}%
\S$\6
$\\{primitive}(\.{"hyphenchar"},\39\\{assign\_font\_int},\390)$;\5
$\\{primitive}(\.{"skewchar"},\39\\{assign\_font\_int},\391)$;\par
\fi

\M1255. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{assign\_font\_int}: \37\&{if} $\\{chr\_code}=0$ \1\&{then}\5
$\\{print\_esc}(\.{"hyphenchar"})$\6
\4\&{else} $\\{print\_esc}(\.{"skewchar"})$;\2\par
\fi

\M1256. Here is where the information for a new font gets loaded.

\Y\P$\4\X1217:Assignments\X\mathrel{+}\S$\6
\4\\{def\_font}: \37$\\{new\_font}(\|a)$;\par
\fi

\M1257. \P$\X1215:Declare subprocedures for \\{prefixed\_command}\X\mathrel{+}%
\S$\6
\4\&{procedure}\1\  \37$\\{new\_font}(\|a:\\{small\_number})$;\6
\4\&{label} \37\\{common\_ending};\6
\4\&{var} \37\|u: \37\\{pointer};\C{user's font identifier}\6
\|s: \37\\{scaled};\C{stated ``at'' size, or negative of scaled magnification}\6
\|f: \37\\{internal\_font\_number};\C{runs through existing fonts}\6
\|t: \37\\{str\_number};\C{name for the frozen font identifier}\6
\\{old\_setting}: \37$0\to\\{max\_selector}$;\C{holds \\{selector} setting}\2\6
\&{begin} \37\&{if} $\\{job\_name}=0$ \1\&{then}\5
\\{open\_log\_file};\C{avoid confusing \.{texput} with the font name}\2\6
\\{get\_r\_token};\5
$\|u\K\\{cur\_cs}$;\6
\&{if} $\|u\G\\{hash\_base}$ \1\&{then}\5
$\|t\K\\{text}(\|u)$\6
\4\&{else} \&{if} $\|u\G\\{single\_base}$ \1\&{then}\6
\&{if} $\|u=\\{null\_cs}$ \1\&{then}\5
$\|t\K\.{"FONT"}$\ \&{else} $\|t\K\|u-\\{single\_base}$\2\6
\4\&{else} \&{begin} \37$\\{old\_setting}\K\\{selector}$;\5
$\\{selector}\K\\{new\_string}$;\5
$\\{print}(\.{"FONT"})$;\5
$\\{print}(\|u-\\{active\_base})$;\5
$\\{selector}\K\\{old\_setting}$;\5
$\\{str\_room}(1)$;\5
$\|t\K\\{make\_string}$;\6
\&{end};\2\2\6
$\\{define}(\|u,\39\\{set\_font},\39\\{null\_font})$;\5
\\{scan\_optional\_equals};\5
\\{scan\_file\_name};\5
\X1258:Scan the font size specification\X;\6
\X1260:If this font has already been loaded, set \|f to the internal font
number and \&{goto} \\{common\_ending}\X;\6
$\|f\K\\{read\_font\_info}(\|u,\39\\{cur\_name},\39\\{cur\_area},\39\|s)$;\6
\4\\{common\_ending}: \37$\\{equiv}(\|u)\K\|f$;\5
$\\{eqtb}[\\{font\_id\_base}+\|f]\K\\{eqtb}[\|u]$;\5
$\\{font\_id\_text}(\|f)\K\|t$;\6
\&{end};\par
\fi

\M1258. \P$\X1258:Scan the font size specification\X\S$\6
$\\{name\_in\_progress}\K\\{true}$;\C{this keeps \\{cur\_name} from being
changed}\6
\&{if} $\\{scan\_keyword}(\.{"at"})$ \1\&{then}\5
\X1259:Put the (positive) `at' size into \|s\X\6
\4\&{else} \&{if} $\\{scan\_keyword}(\.{"scaled"})$ \1\&{then}\6
\&{begin} \37\\{scan\_int};\5
$\|s\K-\\{cur\_val}$;\6
\&{if} $(\\{cur\_val}\L0)\V(\\{cur\_val}>32768)$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Illegal\ magnification\ has\ been\ changed\ to%
\ 1000"})$;\6
$\\{help1}(\.{"The\ magnification\ ratio\ must\ be\ between\ 1\ and\
32768."})$;\5
$\\{int\_error}(\\{cur\_val})$;\5
$\|s\K-1000$;\6
\&{end};\2\6
\&{end}\6
\4\&{else} $\|s\K-1000$;\2\2\6
$\\{name\_in\_progress}\K\\{false}$\par
\U section~1257.\fi

\M1259. \P$\X1259:Put the (positive) `at' size into \|s\X\S$\6
\&{begin} \37\\{scan\_normal\_dimen};\5
$\|s\K\\{cur\_val}$;\6
\&{if} $(\|s\L0)\V(\|s\G\O{1000000000})$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"Improper\ \`at\'\ size\ ("})$;\5
$\\{print\_scaled}(\|s)$;\5
$\\{print}(\.{"pt),\ replaced\ by\ 10pt"})$;\5
$\\{help2}(\.{"I\ can\ only\ handle\ fonts\ at\ positive\ sizes\ that\ are"})$\6
$(\.{"less\ than\ 2048pt,\ so\ I\'ve\ changed\ what\ you\ said\ to\ 10pt."})$;\5
\\{error};\5
$\|s\K10\ast\\{unity}$;\6
\&{end};\2\6
\&{end}\par
\U section~1258.\fi

\M1260. When the user gives a new identifier to a font that was previously
loaded,
the new name becomes the font identifier of record. Font names `\.{xyz}' and
`\.{XYZ}' are considered to be different.

\Y\P$\4\X1260:If this font has already been loaded, set \|f to the internal
font number and \&{goto} \\{common\_ending}\X\S$\6
\&{for} $\|f\K\\{font\_base}+1\mathrel{\&{to}}\\{font\_ptr}$ \1\&{do}\6
\&{if} $\\{str\_eq\_str}(\\{font\_name}[\|f],\39\\{cur\_name})\W\\{str\_eq%
\_str}(\\{font\_area}[\|f],\39\\{cur\_area})$ \1\&{then}\6
\&{begin} \37\&{if} $\|s>0$ \1\&{then}\6
\&{begin} \37\&{if} $\|s=\\{font\_size}[\|f]$ \1\&{then}\5
\&{goto} \37\\{common\_ending};\2\6
\&{end}\6
\4\&{else} \&{if} $\\{font\_size}[\|f]=\\{xn\_over\_d}(\\{font\_dsize}[\|f],%
\39-\|s,\391000)$ \1\&{then}\5
\&{goto} \37\\{common\_ending};\2\2\6
\&{end}\2\2\par
\U section~1257.\fi

\M1261. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{set\_font}: \37\&{begin} \37$\\{print}(\.{"select\ font\ "})$;\5
$\\{print}(\\{font\_name}[\\{chr\_code}])$;\6
\&{if} $\\{font\_size}[\\{chr\_code}]\I\\{font\_dsize}[\\{chr\_code}]$ \1%
\&{then}\6
\&{begin} \37$\\{print}(\.{"\ at\ "})$;\5
$\\{print\_scaled}(\\{font\_size}[\\{chr\_code}])$;\5
$\\{print}(\.{"pt"})$;\6
\&{end};\2\6
\&{end};\par
\fi

\M1262. \P$\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}%
\S$\6
$\\{primitive}(\.{"batchmode"},\39\\{set\_interaction},\39\\{batch\_mode})$;\5
$\\{primitive}(\.{"nonstopmode"},\39\\{set\_interaction},\39\\{nonstop%
\_mode})$;\5
$\\{primitive}(\.{"scrollmode"},\39\\{set\_interaction},\39\\{scroll\_mode})$;\5
$\\{primitive}(\.{"errorstopmode"},\39\\{set\_interaction},\39\\{error\_stop%
\_mode})$;\par
\fi

\M1263. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{set\_interaction}: \37\&{case} $\\{chr\_code}$ \1\&{of}\6
\4\\{batch\_mode}: \37$\\{print\_esc}(\.{"batchmode"})$;\6
\4\\{nonstop\_mode}: \37$\\{print\_esc}(\.{"nonstopmode"})$;\6
\4\\{scroll\_mode}: \37$\\{print\_esc}(\.{"scrollmode"})$;\6
\4\&{othercases} \37$\\{print\_esc}(\.{"errorstopmode"})$\2\6
\&{endcases};\par
\fi

\M1264. \P$\X1217:Assignments\X\mathrel{+}\S$\6
\4\\{set\_interaction}: \37\\{new\_interaction};\par
\fi

\M1265. \P$\X1215:Declare subprocedures for \\{prefixed\_command}\X\mathrel{+}%
\S$\6
\4\&{procedure}\1\  \37\\{new\_interaction};\2\6
\&{begin} \37\\{print\_ln};\5
$\\{interaction}\K\\{cur\_chr}$;\5
\X75:Initialize the print \\{selector} based on \\{interaction}\X;\6
\&{if} $\\{job\_name}\I0$ \1\&{then}\5
$\\{selector}\K\\{selector}+2$;\2\6
\&{end};\par
\fi

\M1266. The \.{\\afterassignment} command puts a token into the global
variable \\{after\_token}. This global variable is examined just after
every assignment has been performed.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{after\_token}: \37\\{halfword};\C{zero, or a saved token}\par
\fi

\M1267. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{after\_token}\K0$;\par
\fi

\M1268. \P$\X1210:Cases of \\{main\_control} that don't depend on \\{mode}\X%
\mathrel{+}\S$\6
\4$\\{any\_mode}(\\{after\_assignment})$: \37\&{begin} \37\\{get\_token};\5
$\\{after\_token}\K\\{cur\_tok}$;\6
\&{end};\par
\fi

\M1269. \P$\X1269:Insert a token saved by \.{\\afterassignment}, if any\X\S$\6
\&{if} $\\{after\_token}\I0$ \1\&{then}\6
\&{begin} \37$\\{cur\_tok}\K\\{after\_token}$;\5
\\{back\_input};\5
$\\{after\_token}\K0$;\6
\&{end}\2\par
\U section~1211.\fi

\M1270. Here is a procedure that might be called `Get the next non-blank
non-relax
non-call non-assignment token'.

\Y\P$\4\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{do\_assignments};\6
\4\&{label} \37\\{exit};\2\6
\&{begin} \37\~ \1\&{loop}\6
\&{begin} \37\X404:Get the next non-blank non-relax non-call token\X;\6
\&{if} $\\{cur\_cmd}\L\\{max\_non\_prefixed\_command}$ \1\&{then}\5
\&{return};\2\6
\\{prefixed\_command};\6
\&{end};\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M1271. \P$\X1210:Cases of \\{main\_control} that don't depend on \\{mode}\X%
\mathrel{+}\S$\6
\4$\\{any\_mode}(\\{after\_group})$: \37\&{begin} \37\\{get\_token};\5
$\\{save\_for\_after}(\\{cur\_tok})$;\6
\&{end};\par
\fi

\M1272. Files for \.{\\read} are opened and closed by the \\{in\_stream}
command.

\Y\P$\4\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}\S$\6
$\\{primitive}(\.{"openin"},\39\\{in\_stream},\391)$;\5
$\\{primitive}(\.{"closein"},\39\\{in\_stream},\390)$;\par
\fi

\M1273. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{in\_stream}: \37\&{if} $\\{chr\_code}=0$ \1\&{then}\5
$\\{print\_esc}(\.{"closein"})$\6
\4\&{else} $\\{print\_esc}(\.{"openin"})$;\2\par
\fi

\M1274. \P$\X1210:Cases of \\{main\_control} that don't depend on \\{mode}\X%
\mathrel{+}\S$\6
\4$\\{any\_mode}(\\{in\_stream})$: \37\\{open\_or\_close\_in};\par
\fi

\M1275. \P$\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{open\_or\_close\_in};\6
\4\&{var} \37\|c: \37$0\to1$;\C{1 for \.{\\openin}, 0 for \.{\\closein}}\6
\|n: \37$0\to15$;\C{stream number}\2\6
\&{begin} \37$\|c\K\\{cur\_chr}$;\5
\\{scan\_four\_bit\_int};\5
$\|n\K\\{cur\_val}$;\6
\&{if} $\\{read\_open}[\|n]\I\\{closed}$ \1\&{then}\6
\&{begin} \37$\\{a\_close}(\\{read\_file}[\|n])$;\5
$\\{read\_open}[\|n]\K\\{closed}$;\6
\&{end};\2\6
\&{if} $\|c\I0$ \1\&{then}\6
\&{begin} \37\\{scan\_optional\_equals};\5
\\{scan\_file\_name};\6
\&{if} $\\{cur\_ext}=\.{""}$ \1\&{then}\5
$\\{cur\_ext}\K\.{".tex"}$;\2\6
\\{pack\_cur\_name};\6
\&{if} $\\{a\_open\_in}(\\{read\_file}[\|n])$ \1\&{then}\5
$\\{read\_open}[\|n]\K\\{just\_open}$;\2\6
\&{end};\2\6
\&{end};\par
\fi

\M1276. The user can issue messages to the terminal, regardless of the
current mode.

\Y\P$\4\X1210:Cases of \\{main\_control} that don't depend on \\{mode}\X%
\mathrel{+}\S$\6
\4$\\{any\_mode}(\\{message})$: \37\\{issue\_message};\par
\fi

\M1277. \P$\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}%
\S$\6
$\\{primitive}(\.{"message"},\39\\{message},\390)$;\5
$\\{primitive}(\.{"errmessage"},\39\\{message},\391)$;\par
\fi

\M1278. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{message}: \37\&{if} $\\{chr\_code}=0$ \1\&{then}\5
$\\{print\_esc}(\.{"message"})$\6
\4\&{else} $\\{print\_esc}(\.{"errmessage"})$;\2\par
\fi

\M1279. \P$\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{issue\_message};\6
\4\&{var} \37\\{old\_setting}: \37$0\to\\{max\_selector}$;\C{holds \\{selector}
setting}\6
\|c: \37$0\to1$;\C{identifies \.{\\message} and \.{\\errmessage}}\6
\|s: \37\\{str\_number};\C{the message}\2\6
\&{begin} \37$\|c\K\\{cur\_chr}$;\5
$\\{link}(\\{garbage})\K\\{scan\_toks}(\\{false},\39\\{true})$;\5
$\\{old\_setting}\K\\{selector}$;\5
$\\{selector}\K\\{new\_string}$;\5
$\\{token\_show}(\\{def\_ref})$;\5
$\\{selector}\K\\{old\_setting}$;\5
$\\{flush\_list}(\\{def\_ref})$;\5
$\\{str\_room}(1)$;\5
$\|s\K\\{make\_string}$;\6
\&{if} $\|c=0$ \1\&{then}\5
\X1280:Print string \|s on the terminal\X\6
\4\&{else} \X1283:Print string \|s as an error message\X;\2\6
\\{flush\_string};\6
\&{end};\par
\fi

\M1280. \P$\X1280:Print string \|s on the terminal\X\S$\6
\&{begin} \37\&{if} $\\{term\_offset}+\\{length}(\|s)>\\{max\_print\_line}-2$ %
\1\&{then}\5
\\{print\_ln}\6
\4\&{else} \&{if} $(\\{term\_offset}>0)\V(\\{file\_offset}>0)$ \1\&{then}\5
$\\{print\_char}(\.{"\ "})$;\2\2\6
$\\{print}(\|s)$;\5
\\{update\_terminal};\6
\&{end}\par
\U section~1279.\fi

\M1281. If \.{\\errmessage} occurs often in \\{scroll\_mode}, without
user-defined
\.{\\errhelp}, we don't want to give a long help message each time. So we
give a verbose explanation only once.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{long\_help\_seen}: \37\\{boolean};\C{has the long \.{\\errmessage} help
been used?}\par
\fi

\M1282. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{long\_help\_seen}\K\\{false}$;\par
\fi

\M1283. \P$\X1283:Print string \|s as an error message\X\S$\6
\&{begin} \37$\\{print\_err}(\|s)$;\6
\&{if} $\\{err\_help}\I\\{null}$ \1\&{then}\5
$\\{use\_err\_help}\K\\{true}$\6
\4\&{else} \&{if} $\\{long\_help\_seen}$ \1\&{then}\5
$\\{help1}(\.{"(That\ was\ another\ \\errmessage.)"})$\6
\4\&{else} \&{begin} \37\&{if} $\\{interaction}<\\{error\_stop\_mode}$ \1%
\&{then}\5
$\\{long\_help\_seen}\K\\{true}$;\2\6
$\\{help4}(\.{"This\ error\ message\ was\ generated\ by\ an\ \\errmessage"})$\6
$(\.{"command,\ so\ I\ can\'t\ give\ any\ explicit\ help."})$\6
$(\.{"Pretend\ that\ you\'re\ Hercule\ Poirot:\ Examine\ all\ clues,"})$\6
$(\.{"and\ deduce\ the\ truth\ by\ order\ and\ method."})$;\6
\&{end};\2\2\6
\\{error};\5
$\\{use\_err\_help}\K\\{false}$;\6
\&{end}\par
\U section~1279.\fi

\M1284. The \\{error} routine calls on \\{give\_err\_help} if help is requested
from
the \\{err\_help} parameter.

\Y\P\4\&{procedure}\1\  \37\\{give\_err\_help};\2\6
\&{begin} \37$\\{token\_show}(\\{err\_help})$;\6
\&{end};\par
\fi

\M1285. The \.{\\uppercase} and \.{\\lowercase} commands are implemented by
building a token list and then changing the cases of the letters in it.

\Y\P$\4\X1210:Cases of \\{main\_control} that don't depend on \\{mode}\X%
\mathrel{+}\S$\6
\4$\\{any\_mode}(\\{case\_shift})$: \37\\{shift\_case};\par
\fi

\M1286. \P$\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}%
\S$\6
$\\{primitive}(\.{"lowercase"},\39\\{case\_shift},\39\\{lc\_code\_base})$;\5
$\\{primitive}(\.{"uppercase"},\39\\{case\_shift},\39\\{uc\_code\_base})$;\par
\fi

\M1287. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{case\_shift}: \37\&{if} $\\{chr\_code}=\\{lc\_code\_base}$ \1\&{then}\5
$\\{print\_esc}(\.{"lowercase"})$\6
\4\&{else} $\\{print\_esc}(\.{"uppercase"})$;\2\par
\fi

\M1288. \P$\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{shift\_case};\6
\4\&{var} \37\|b: \37\\{pointer};\C{\\{lc\_code\_base} or \\{uc\_code\_base}}\6
\|p: \37\\{pointer};\C{runs through the token list}\6
\|t: \37\\{halfword};\C{token}\6
\|c: \37\\{eight\_bits};\C{character code}\2\6
\&{begin} \37$\|b\K\\{cur\_chr}$;\5
$\|p\K\\{scan\_toks}(\\{false},\39\\{false})$;\5
$\|p\K\\{link}(\\{def\_ref})$;\6
\&{while} $\|p\I\\{null}$ \1\&{do}\6
\&{begin} \37\X1289:Change the case of the token in \|p, if a change is
appropriate\X;\6
$\|p\K\\{link}(\|p)$;\6
\&{end};\2\6
$\\{back\_list}(\\{link}(\\{def\_ref}))$;\5
$\\{free\_avail}(\\{def\_ref})$;\C{omit reference count}\6
\&{end};\par
\fi

\M1289. When the case of a \\{chr\_code} changes, we don't change the \\{cmd}.
We also change active characters, using the fact that \\{cs\_token\_flag}
is a multiple of~256.

\Y\P$\4\X1289:Change the case of the token in \|p, if a change is appropriate\X%
\S$\6
$\|t\K\\{info}(\|p)$;\6
\&{if} $\|t<\\{cs\_token\_flag}+\\{single\_base}$ \1\&{then}\6
\&{begin} \37\&{if} $\|t\G\\{cs\_token\_flag}$ \1\&{then}\5
$\|t\K\|t-\\{active\_base}$;\2\6
$\|c\K\|t\mathbin{\&{mod}}256$;\6
\&{if} $\|c<128$ \1\&{then}\6
\&{if} $\\{equiv}(\|b+\|c)\I0$ \1\&{then}\5
$\|t\K256\ast(\|t\mathbin{\&{div}}256)+\\{equiv}(\|b+\|c)$;\2\2\6
\&{if} $\|t\G\\{cs\_token\_flag}$ \1\&{then}\5
$\\{info}(\|p)\K\|t+\\{active\_base}$\6
\4\&{else} $\\{info}(\|p)\K\|t$;\2\6
\&{end}\2\par
\U section~1288.\fi

\M1290. We come finally to the last pieces missing from \\{main\_control},
namely the
`\.{\\show}' commands that are useful when debugging.

\Y\P$\4\X1210:Cases of \\{main\_control} that don't depend on \\{mode}\X%
\mathrel{+}\S$\6
\4$\\{any\_mode}(\\{xray})$: \37\\{show\_whatever};\par
\fi

\M1291. \P\D \37$\\{show\_code}=0$\C{ \.{\\show} }\par
\P\D \37$\\{show\_box\_code}=1$\C{ \.{\\showbox} }\par
\P\D \37$\\{show\_the\_code}=2$\C{ \.{\\showthe} }\par
\P\D \37$\\{show\_lists}=3$\C{ \.{\\showlists} }\par
\Y\P$\4\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}\S$\6
$\\{primitive}(\.{"show"},\39\\{xray},\39\\{show\_code})$;\5
$\\{primitive}(\.{"showbox"},\39\\{xray},\39\\{show\_box\_code})$;\5
$\\{primitive}(\.{"showthe"},\39\\{xray},\39\\{show\_the\_code})$;\5
$\\{primitive}(\.{"showlists"},\39\\{xray},\39\\{show\_lists})$;\par
\fi

\M1292. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{xray}: \37\&{case} $\\{chr\_code}$ \1\&{of}\6
\4\\{show\_box\_code}: \37$\\{print\_esc}(\.{"showbox"})$;\6
\4\\{show\_the\_code}: \37$\\{print\_esc}(\.{"showthe"})$;\6
\4\\{show\_lists}: \37$\\{print\_esc}(\.{"showlists"})$;\6
\4\&{othercases} \37$\\{print\_esc}(\.{"show"})$\2\6
\&{endcases};\par
\fi

\M1293. \P$\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{show\_whatever};\6
\4\&{label} \37\\{common\_ending};\6
\4\&{var} \37\|p: \37\\{pointer};\C{tail of a token list to show}\2\6
\&{begin} \37\&{case} $\\{cur\_chr}$ \1\&{of}\6
\4\\{show\_lists}: \37\&{begin} \37\\{begin\_diagnostic};\5
\\{show\_activities};\6
\&{end};\6
\4\\{show\_box\_code}: \37\X1296:Show the current contents of a box\X;\6
\4\\{show\_code}: \37\X1294:Show the current meaning of a token, then \&{goto} %
\\{common\_ending}\X;\6
\4\&{othercases} \37\X1297:Show the current value of some parameter or
register, then \&{goto} \\{common\_ending}\X\2\6
\&{endcases};\6
\X1298:Complete a potentially long \.{\\show} command\X;\6
\4\\{common\_ending}: \37\&{if} $\\{interaction}<\\{error\_stop\_mode}$ \1%
\&{then}\6
\&{begin} \37\\{help0};\5
$\\{decr}(\\{error\_count})$;\6
\&{end}\6
\4\&{else} \&{if} $\\{tracing\_online}>0$ \1\&{then}\6
\&{begin} \37\hbox{}\6
$\\{help3}(\.{"This\ isn\'t\ an\ error\ message;\ I\'m\ just\ \\showing\
something."})$\6
$(\.{"Type\ \`I\\show...\'\ to\ show\ more\ (e.g.,\ \\show\\cs,"})$\6
$(\.{"\\showthe\\count10,\ \\showbox255,\ \\showlists)."})$;\6
\&{end}\6
\4\&{else} \&{begin} \37\hbox{}\6
$\\{help5}(\.{"This\ isn\'t\ an\ error\ message;\ I\'m\ just\ \\showing\
something."})$\6
$(\.{"Type\ \`I\\show...\'\ to\ show\ more\ (e.g.,\ \\show\\cs,"})$\6
$(\.{"\\showthe\\count10,\ \\showbox255,\ \\showlists)."})$\6
$(\.{"And\ type\ \`I\\tracingonline=1\\show...\'\ to\ show\ boxes\ and"})$\6
$(\.{"lists\ on\ your\ terminal\ as\ well\ as\ in\ the\ transcript\ file."})$;\6
\&{end};\2\2\6
\\{error};\6
\&{end};\par
\fi

\M1294. \P$\X1294:Show the current meaning of a token, then \&{goto} \\{common%
\_ending}\X\S$\6
\&{begin} \37\\{get\_token};\6
\&{if} $\\{interaction}=\\{error\_stop\_mode}$ \1\&{then}\5
\\{wake\_up\_terminal};\2\6
$\\{print\_nl}(\.{">\ "})$;\6
\&{if} $\\{cur\_cs}\I0$ \1\&{then}\6
\&{begin} \37$\\{sprint\_cs}(\\{cur\_cs})$;\5
$\\{print\_char}(\.{"="})$;\6
\&{end};\2\6
\\{print\_meaning};\5
\&{goto} \37\\{common\_ending};\6
\&{end}\par
\U section~1293.\fi

\M1295. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{undefined\_cs}: \37$\\{print}(\.{"undefined"})$;\6
\4\\{call}: \37$\\{print}(\.{"macro"})$;\6
\4\\{long\_call}: \37$\\{print\_esc}(\.{"long\ macro"})$;\6
\4\\{outer\_call}: \37$\\{print\_esc}(\.{"outer\ macro"})$;\6
\4\\{long\_outer\_call}: \37\&{begin} \37$\\{print\_esc}(\.{"long"})$;\5
$\\{print\_esc}(\.{"outer\ macro"})$;\6
\&{end};\6
\4\\{end\_template}: \37$\\{print\_esc}(\.{"outer\ endtemplate"})$;\par
\fi

\M1296. \P$\X1296:Show the current contents of a box\X\S$\6
\&{begin} \37\\{scan\_eight\_bit\_int};\5
\\{begin\_diagnostic};\5
$\\{print\_nl}(\.{">\ \\box"})$;\5
$\\{print\_int}(\\{cur\_val})$;\5
$\\{print\_char}(\.{"="})$;\6
\&{if} $\\{box}(\\{cur\_val})=\\{null}$ \1\&{then}\5
$\\{print}(\.{"void"})$\6
\4\&{else} $\\{show\_box}(\\{box}(\\{cur\_val}))$;\2\6
\&{end}\par
\U section~1293.\fi

\M1297. \P$\X1297:Show the current value of some parameter or register, then %
\&{goto} \\{common\_ending}\X\S$\6
\&{begin} \37$\|p\K\\{the\_toks}$;\6
\&{if} $\\{interaction}=\\{error\_stop\_mode}$ \1\&{then}\5
\\{wake\_up\_terminal};\2\6
$\\{print\_nl}(\.{">\ "})$;\5
$\\{token\_show}(\\{temp\_head})$;\5
$\\{flush\_list}(\\{link}(\\{temp\_head}))$;\5
\&{goto} \37\\{common\_ending};\6
\&{end}\par
\U section~1293.\fi

\M1298. \P$\X1298:Complete a potentially long \.{\\show} command\X\S$\6
$\\{end\_diagnostic}(\\{true})$;\5
$\\{print\_err}(\.{"OK"})$;\6
\&{if} $\\{selector}=\\{term\_and\_log}$ \1\&{then}\6
\&{if} $\\{tracing\_online}\L0$ \1\&{then}\6
\&{begin} \37$\\{selector}\K\\{term\_only}$;\5
$\\{print}(\.{"\ (see\ the\ transcript\ file)"})$;\5
$\\{selector}\K\\{term\_and\_log}$;\6
\&{end}\2\2\par
\U section~1293.\fi

\N1299.  \[50] Dumping and undumping the tables.
After \.{INITEX} has seen a collection of fonts and macros, it
can write all the necessary information on an auxiliary file so
that production versions of \TeX\ are able to initialize their
memory at high speed. The present section of the program takes
care of such output and input. We shall consider simultaneously
the processes of storing and restoring,
so that the inverse relation between them is clear.

The global variable \\{format\_ident} is a string that is printed right
after the \\{banner} line when \TeX\ is ready to start. For \.{INITEX} this
string says simply `\.{(INITEX)}'; for other versions of \TeX\ it says,
for example, `\.{(preloaded format=plain 82.11.19)}', showing the year,
month, and day that the format file was created. We have $\\{format\_ident}=0$
before \TeX's tables are loaded.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{format\_ident}: \37\\{str\_number};\par
\fi

\M1300. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{format\_ident}\K0$;\par
\fi

\M1301. \P$\X164:Initialize table entries (done by \.{INITEX} only)\X%
\mathrel{+}\S$\6
$\\{format\_ident}\K\.{"\ (INITEX)"}$;\par
\fi

\M1302. \P$\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\&{init} \37\&{procedure}\1\  \37\\{store\_fmt\_file};\6
\4\&{label} \37$\\{found1},\39\\{found2},\39\\{done1},\39\\{done2}$;\6
\4\&{var} \37$\|j,\39\|k,\39\|l$: \37\\{integer};\C{all-purpose indices}\6
$\|p,\39\|q$: \37\\{pointer};\C{all-purpose pointers}\6
\|x: \37\\{integer};\C{something to dump}\6
\|w: \37\\{four\_quarters};\C{four ASCII codes}\2\6
\&{begin} \37\X1304:If dumping is not allowed, abort\X;\6
\X1328:Create the \\{format\_ident}, open the format file, and inform the user
that dumping has begun\X;\6
\X1307:Dump constants for consistency check\X;\6
\X1309:Dump the string pool\X;\6
\X1311:Dump the dynamic memory\X;\6
\X1313:Dump the table of equivalents\X;\6
\X1320:Dump the font information\X;\6
\X1324:Dump the hyphenation tables\X;\6
\X1326:Dump a couple more things and the closing check word\X;\6
\X1329:Close the format file\X;\6
\&{end};\6
\&{tini}\par
\fi

\M1303. Corresponding to the procedure that dumps a format file, we have a
function
that reads one in. The function returns \\{false} if the dumped format is
incompatible with the present \TeX\ table sizes, etc.

\Y\P\D \37$\\{bad\_fmt}=6666$\C{go here if the format file is unacceptable}\par
\P\D \37$\\{too\_small}(\#)\S$\1\6
\&{begin} \37\\{wake\_up\_terminal};\5
$\\{wterm\_ln}(\.{\'---!\ Must\ increase\ the\ \'},\39\#)$;\5
\&{goto} \37\\{bad\_fmt};\6
\&{end}\2\par
\Y\P\hbox{\4}\X524:Declare the function called \\{open\_fmt\_file}\X\6
\4\&{function}\1\  \37\\{load\_fmt\_file}: \37\\{boolean};\6
\4\&{label} \37$\\{bad\_fmt},\39\\{exit}$;\6
\4\&{var} \37$\|j,\39\|k$: \37\\{integer};\C{all-purpose indices}\6
$\|p,\39\|q$: \37\\{pointer};\C{all-purpose pointers}\6
\|x: \37\\{integer};\C{something undumped}\6
\|w: \37\\{four\_quarters};\C{four ASCII codes}\2\6
\&{begin} \37\X1308:Undump constants for consistency check\X;\6
\X1310:Undump the string pool\X;\6
\X1312:Undump the dynamic memory\X;\6
\X1314:Undump the table of equivalents\X;\6
\X1321:Undump the font information\X;\6
\X1325:Undump the hyphenation tables\X;\6
\X1327:Undump a couple more things and the closing check word\X;\6
$\\{load\_fmt\_file}\K\\{true}$;\5
\&{return};\C{it worked!}\6
\4\\{bad\_fmt}: \37\\{wake\_up\_terminal};\5
$\\{wterm\_ln}(\.{\'(Fatal\ format\ file\ error;\ I\'}\.{\'m\ stymied)\'})$;\5
$\\{load\_fmt\_file}\K\\{false}$;\6
\4\\{exit}: \37\&{end};\par
\fi

\M1304. The user is not allowed to dump a format file unless $\\{save\_ptr}=0$.
This condition implies that $\\{cur\_level}=\\{level\_one}$, hence
the \\{xeq\_level} array is constant and it need not be dumped.

\Y\P$\4\X1304:If dumping is not allowed, abort\X\S$\6
\&{if} $\\{save\_ptr}\I0$ \1\&{then}\6
\&{begin} \37$\\{print\_err}(\.{"You\ can\'t\ dump\ inside\ a\ group"})$;\5
$\\{help1}(\.{"\`\{...\\dump\}\'\ is\ a\ no-no."})$;\5
\\{succumb};\6
\&{end}\2\par
\U section~1302.\fi

\M1305. Format files consist of \\{memory\_word} items, and we use the
following
macros to dump words of different types:

\Y\P\D \37$\\{dump\_wd}(\#)\S$\1\6
\&{begin} \37$\\{fmt\_file}\↑\K\#$;\5
$\\{put}(\\{fmt\_file})$;\ \&{end}\2\par
\P\D \37$\\{dump\_int}(\#)\S$\1\6
\&{begin} \37$\\{fmt\_file}\↑.\\{int}\K\#$;\5
$\\{put}(\\{fmt\_file})$;\ \&{end}\2\par
\P\D \37$\\{dump\_hh}(\#)\S$\1\6
\&{begin} \37$\\{fmt\_file}\↑.\\{hh}\K\#$;\5
$\\{put}(\\{fmt\_file})$;\ \&{end}\2\par
\P\D \37$\\{dump\_qqqq}(\#)\S$\1\6
\&{begin} \37$\\{fmt\_file}\↑.\\{qqqq}\K\#$;\5
$\\{put}(\\{fmt\_file})$;\ \&{end}\2\par
\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{fmt\_file}: \37\\{word\_file};\C{for input or output of format
information}\par
\fi

\M1306. The inverse macros are slightly more complicated, since we need to
check
the range of the values we are reading in. We say `$\\{undump}(\|a)(\|b)(\|x)$'
to
read an integer value \|x that is supposed to be in the range $\|a\L\|x\L\|b$.

\Y\P\D \37$\\{undump\_wd}(\#)\S$\1\6
\&{begin} \37$\\{get}(\\{fmt\_file})$;\5
$\#\K\\{fmt\_file}\↑$;\ \&{end}\2\par
\P\D \37$\\{undump\_int}(\#)\S$\1\6
\&{begin} \37$\\{get}(\\{fmt\_file})$;\5
$\#\K\\{fmt\_file}\↑.\\{int}$;\ \&{end}\2\par
\P\D \37$\\{undump\_hh}(\#)\S$\1\6
\&{begin} \37$\\{get}(\\{fmt\_file})$;\5
$\#\K\\{fmt\_file}\↑.\\{hh}$;\ \&{end}\2\par
\P\D \37$\\{undump\_qqqq}(\#)\S$\1\6
\&{begin} \37$\\{get}(\\{fmt\_file})$;\5
$\#\K\\{fmt\_file}\↑.\\{qqqq}$;\ \&{end}\2\par
\P\D \37$\\{undump\_end\_end}(\#)\S\#\K\|x$;\ \&{end} \par
\P\D $\\{undump\_end}(\#)\S(\|x>\#)$ \&{then} \&{goto} \37\\{bad\_fmt}\ %
\&{else} \37\\{undump\_end\_end}\par
\P\D $\\{undump}(\#)\S$ \6
\&{begin} \37$\\{undump\_int}(\|x)$;  \6
\&{if} $(\|x<\#)\V\\{undump\_end}$\par
\P\D \37$\\{undump\_size\_end\_end}(\#)\S\\{too\_small}(\#)$\ \&{else} \37%
\\{undump\_end\_end}\par
\P\D \37$\\{undump\_size\_end}(\#)\S$\1\6
\&{if} $\|x>\#$ \1\&{then}\5
\\{undump\_size\_end\_end}\2\2\par
\P\D $\\{undump\_size}(\#)\S$ \6
\&{begin} \37$\\{undump\_int}(\|x)$;\6
\&{if} $\|x<\#$ \1\&{then}\5
\&{goto} \37\\{bad\_fmt};\2\6
\\{undump\_size\_end}\par
\fi

\M1307. The next few sections of the program should make it clear how we use
the
dump/undump macros.

\Y\P$\4\X1307:Dump constants for consistency check\X\S$\6
$\\{dump\_int}(\))$;\6
$\\{dump\_int}(\\{mem\_bot})$;\6
$\\{dump\_int}(\\{mem\_top})$;\6
$\\{dump\_int}(\\{eqtb\_size})$;\6
$\\{dump\_int}(\\{hash\_prime})$;\6
$\\{dump\_int}(\\{hyph\_size})$\par
\U section~1302.\fi

\M1308. Sections of a \.{WEB} program that are ``commented out'' still
contribute
strings to the string pool; therefore \.{INITEX} and \TeX\ will have
the same strings. (And it is, of course, a good thing that they do.)

\Y\P$\4\X1308:Undump constants for consistency check\X\S$\6
$\|x\K\\{fmt\_file}\↑.\\{int}$;\6
\&{if} $\|x\I\)$ \1\&{then}\5
\&{goto} \37\\{bad\_fmt};\C{check that strings are the same}\2\6
$\\{undump\_int}(\|x)$;\6
\&{if} $\|x\I\\{mem\_bot}$ \1\&{then}\5
\&{goto} \37\\{bad\_fmt};\2\6
$\\{undump\_int}(\|x)$;\6
\&{if} $\|x\I\\{mem\_top}$ \1\&{then}\5
\&{goto} \37\\{bad\_fmt};\2\6
$\\{undump\_int}(\|x)$;\6
\&{if} $\|x\I\\{eqtb\_size}$ \1\&{then}\5
\&{goto} \37\\{bad\_fmt};\2\6
$\\{undump\_int}(\|x)$;\6
\&{if} $\|x\I\\{hash\_prime}$ \1\&{then}\5
\&{goto} \37\\{bad\_fmt};\2\6
$\\{undump\_int}(\|x)$;\6
\&{if} $\|x\I\\{hyph\_size}$ \1\&{then}\5
\&{goto} \37\\{bad\_fmt}\2\par
\U section~1303.\fi

\M1309. \P\D \37$\\{dump\_four\_ASCII}\S\|w.\\{b0}\K\\{str\_pool}[\|k]$;\5
$\|w.\\{b1}\K\\{str\_pool}[\|k+1]$;\5
$\|w.\\{b2}\K\\{str\_pool}[\|k+2]$;\5
$\|w.\\{b3}\K\\{str\_pool}[\|k+3]$;\5
$\\{dump\_qqqq}(\|w)$\par
\Y\P$\4\X1309:Dump the string pool\X\S$\6
$\\{dump\_int}(\\{pool\_ptr})$;\5
$\\{dump\_int}(\\{str\_ptr})$;\6
\&{for} $\|k\K0\mathrel{\&{to}}\\{str\_ptr}$ \1\&{do}\5
$\\{dump\_int}(\\{str\_start}[\|k])$;\2\6
$\|k\K0$;\6
\&{while} $\|k+4<\\{pool\_ptr}$ \1\&{do}\6
\&{begin} \37\\{dump\_four\_ASCII};\5
$\|k\K\|k+4$;\6
\&{end};\2\6
$\|k\K\\{pool\_ptr}-4$;\5
\\{dump\_four\_ASCII};\5
\\{print\_ln};\5
$\\{print\_int}(\\{str\_ptr})$;\5
$\\{print}(\.{"\ strings\ of\ total\ length\ "})$;\5
$\\{print\_int}(\\{pool\_ptr})$\par
\U section~1302.\fi

\M1310. \P\D \37$\\{undump\_four\_ASCII}\S\\{undump\_qqqq}(\|w)$;\5
$\\{str\_pool}[\|k]\K\|w.\\{b0}$;\5
$\\{str\_pool}[\|k+1]\K\|w.\\{b1}$;\5
$\\{str\_pool}[\|k+2]\K\|w.\\{b2}$;\5
$\\{str\_pool}[\|k+3]\K\|w.\\{b3}$\par
\Y\P$\4\X1310:Undump the string pool\X\S$\6
$\\{undump\_size}(0)(\\{pool\_size})(\.{\'string\ pool\ size\'})(\\{pool%
\_ptr})$;\5
$\\{undump\_size}(0)(\\{max\_strings})(\.{\'max\ strings\'})(\\{str\_ptr})$;\6
\&{for} $\|k\K0\mathrel{\&{to}}\\{str\_ptr}$ \1\&{do}\5
$\\{undump}(0)(\\{pool\_ptr})(\\{str\_start}[\|k])$;\2\6
$\|k\K0$;\6
\&{while} $\|k+4<\\{pool\_ptr}$ \1\&{do}\6
\&{begin} \37\\{undump\_four\_ASCII};\5
$\|k\K\|k+4$;\6
\&{end};\2\6
$\|k\K\\{pool\_ptr}-4$;\5
\\{undump\_four\_ASCII}\par
\U section~1303.\fi

\M1311. By sorting the list of available spaces in the variable-size portion of
\\{mem}, we are usually able to get by without having to dump very much
of the dynamic memory.

We recompute \\{var\_used} and \\{dyn\_used}, so that \.{INITEX} dumps valid
information even when it has not been gathering statistics.

\Y\P$\4\X1311:Dump the dynamic memory\X\S$\6
\\{sort\_avail};\5
$\\{var\_used}\K0$;\5
$\\{dump\_int}(\\{lo\_mem\_max})$;\5
$\\{dump\_int}(\\{rover})$;\5
$\|p\K\\{mem\_bot}$;\5
$\|q\K\\{rover}$;\5
$\|x\K0$;\6
\1\&{repeat} \37\&{for} $\|k\K\|p\mathrel{\&{to}}\|q+1$ \1\&{do}\5
$\\{dump\_wd}(\\{mem}[\|k])$;\2\6
$\|x\K\|x+\|q+2-\|p$;\5
$\\{var\_used}\K\\{var\_used}+\|q-\|p$;\5
$\|p\K\|q+\\{node\_size}(\|q)$;\5
$\|q\K\\{rlink}(\|q)$;\6
\4\&{until}\5
$\|q=\\{rover}$;\2\6
$\\{var\_used}\K\\{var\_used}+\\{lo\_mem\_max}-\|p$;\5
$\\{dyn\_used}\K\\{mem\_end}+1-\\{hi\_mem\_min}$;\6
\&{for} $\|k\K\|p\mathrel{\&{to}}\\{lo\_mem\_max}$ \1\&{do}\5
$\\{dump\_wd}(\\{mem}[\|k])$;\2\6
$\|x\K\|x+\\{lo\_mem\_max}+1-\|p$;\5
$\\{dump\_int}(\\{hi\_mem\_min})$;\5
$\\{dump\_int}(\\{avail})$;\6
\&{for} $\|k\K\\{hi\_mem\_min}\mathrel{\&{to}}\\{mem\_end}$ \1\&{do}\5
$\\{dump\_wd}(\\{mem}[\|k])$;\2\6
$\|x\K\|x+\\{mem\_end}+1-\\{hi\_mem\_min}$;\5
$\|p\K\\{avail}$;\6
\&{while} $\|p\I\\{null}$ \1\&{do}\6
\&{begin} \37$\\{decr}(\\{dyn\_used})$;\5
$\|p\K\\{link}(\|p)$;\6
\&{end};\2\6
$\\{dump\_int}(\\{var\_used})$;\5
$\\{dump\_int}(\\{dyn\_used})$;\5
\\{print\_ln};\5
$\\{print\_int}(\|x)$;\5
$\\{print}(\.{"\ memory\ locations\ dumped;\ current\ usage\ is\ "})$;\5
$\\{print\_int}(\\{var\_used})$;\5
$\\{print\_char}(\.{"\&"})$;\5
$\\{print\_int}(\\{dyn\_used})$\par
\U section~1302.\fi

\M1312. \P$\X1312:Undump the dynamic memory\X\S$\6
$\\{undump}(\\{lo\_mem\_stat\_max}+1000)(\\{hi\_mem\_stat\_min}-1)(\\{lo\_mem%
\_max})$;\5
$\\{undump}(\\{lo\_mem\_stat\_max}+1)(\\{lo\_mem\_max})(\\{rover})$;\5
$\|p\K\\{mem\_bot}$;\5
$\|q\K\\{rover}$;\5
$\|x\K0$;\6
\1\&{repeat} \37\&{for} $\|k\K\|p\mathrel{\&{to}}\|q+1$ \1\&{do}\5
$\\{undump\_wd}(\\{mem}[\|k])$;\2\6
$\|p\K\|q+\\{node\_size}(\|q)$;\6
\&{if} $(\|p>\\{lo\_mem\_max})\V((\|q\G\\{rlink}(\|q))\W(\\{rlink}(\|q)\I%
\\{rover}))$ \1\&{then}\5
\&{goto} \37\\{bad\_fmt};\2\6
$\|q\K\\{rlink}(\|q)$;\6
\4\&{until}\5
$\|q=\\{rover}$;\2\6
\&{for} $\|k\K\|p\mathrel{\&{to}}\\{lo\_mem\_max}$ \1\&{do}\5
$\\{undump\_wd}(\\{mem}[\|k])$;\2\6
\&{if} $\\{mem\_min}<\\{mem\_bot}-2$ \1\&{then}\C{make more low memory
available}\6
\&{begin} \37$\|p\K\\{llink}(\\{rover})$;\5
$\|q\K\\{mem\_min}+1$;\5
$\\{link}(\\{mem\_min})\K\\{null}$;\5
$\\{info}(\\{mem\_min})\K\\{null}$;\C{we don't use the bottom word}\6
$\\{rlink}(\|p)\K\|q$;\5
$\\{llink}(\\{rover})\K\|q$;\6
$\\{rlink}(\|q)\K\\{rover}$;\5
$\\{llink}(\|q)\K\|p$;\5
$\\{link}(\|q)\K\\{empty\_flag}$;\5
$\\{node\_size}(\|q)\K\\{mem\_bot}-\|q$;\6
\&{end};\2\6
$\\{undump}(\\{lo\_mem\_max}+1)(\\{hi\_mem\_stat\_min})(\\{hi\_mem\_min})$;\5
$\\{undump}(\\{null})(\\{mem\_top})(\\{avail})$;\5
$\\{mem\_end}\K\\{mem\_top}$;\6
\&{for} $\|k\K\\{hi\_mem\_min}\mathrel{\&{to}}\\{mem\_end}$ \1\&{do}\5
$\\{undump\_wd}(\\{mem}[\|k])$;\2\6
$\\{undump\_int}(\\{var\_used})$;\5
$\\{undump\_int}(\\{dyn\_used})$\par
\U section~1303.\fi

\M1313. \P$\X1313:Dump the table of equivalents\X\S$\6
\X1315:Dump regions 1 to 4 of \\{eqtb}\X;\6
\X1316:Dump regions 5 and 6 of \\{eqtb}\X;\6
$\\{dump\_int}(\\{par\_loc})$;\5
$\\{dump\_int}(\\{write\_loc})$;\6
\X1318:Dump the hash table\X\par
\U section~1302.\fi

\M1314. \P$\X1314:Undump the table of equivalents\X\S$\6
\X1317:Undump regions 1 to 6 of \\{eqtb}\X;\6
$\\{undump}(\\{hash\_base})(\\{frozen\_control\_sequence})(\\{par\_loc})$;\5
$\\{par\_token}\K\\{cs\_token\_flag}+\\{par\_loc}$;\6
$\\{undump}(\\{hash\_base})(\\{frozen\_control\_sequence})(\\{write\_loc})$;\6
\X1319:Undump the hash table\X\par
\U section~1303.\fi

\M1315. The table of equivalents usually contains repeated information, so we
dump it
in compressed form: The sequence of $n+2$ values $(n,x_1,\ldots,x_n,m)$ in the
format file represents $n+m$ consecutive entries of \\{eqtb}, with \|m extra
copies of $x_n$, namely $(x_1,\ldots,x_n,x_n,\ldots,x_n)$.

\Y\P$\4\X1315:Dump regions 1 to 4 of \\{eqtb}\X\S$\6
$\|k\K\\{active\_base}$;\6
\1\&{repeat} \37$\|j\K\|k$;\6
\&{while} $\|j<\\{int\_base}-1$ \1\&{do}\6
\&{begin} \37\&{if} $(\\{equiv}(\|j)=\\{equiv}(\|j+1))\W(\\{eq\_type}(\|j)=%
\\{eq\_type}(\|j+1))\W\30(\\{eq\_level}(\|j)=\\{eq\_level}(\|j+1))$ \1\&{then}\5
\&{goto} \37\\{found1};\2\6
$\\{incr}(\|j)$;\6
\&{end};\2\6
$\|l\K\\{int\_base}$;\5
\&{goto} \37\\{done1};\C{$\|j=\\{int\_base}-1$}\6
\4\\{found1}: \37$\\{incr}(\|j)$;\5
$\|l\K\|j$;\6
\&{while} $\|j<\\{int\_base}-1$ \1\&{do}\6
\&{begin} \37\&{if} $(\\{equiv}(\|j)\I\\{equiv}(\|j+1))\V(\\{eq\_type}(\|j)\I%
\\{eq\_type}(\|j+1))\V\30(\\{eq\_level}(\|j)\I\\{eq\_level}(\|j+1))$ \1\&{then}%
\5
\&{goto} \37\\{done1};\2\6
$\\{incr}(\|j)$;\6
\&{end};\2\6
\4\\{done1}: \37$\\{dump\_int}(\|l-\|k)$;\6
\&{while} $\|k<\|l$ \1\&{do}\6
\&{begin} \37$\\{dump\_wd}(\\{eqtb}[\|k])$;\5
$\\{incr}(\|k)$;\6
\&{end};\2\6
$\|k\K\|j+1$;\5
$\\{dump\_int}(\|k-\|l)$;\6
\4\&{until}\5
$\|k=\\{int\_base}$\2\par
\U section~1313.\fi

\M1316. \P$\X1316:Dump regions 5 and 6 of \\{eqtb}\X\S$\6
\1\&{repeat} \37$\|j\K\|k$;\6
\&{while} $\|j<\\{eqtb\_size}$ \1\&{do}\6
\&{begin} \37\&{if} $\\{eqtb}[\|j].\\{int}=\\{eqtb}[\|j+1].\\{int}$ \1\&{then}\5
\&{goto} \37\\{found2};\2\6
$\\{incr}(\|j)$;\6
\&{end};\2\6
$\|l\K\\{eqtb\_size}+1$;\5
\&{goto} \37\\{done2};\C{$\|j=\\{eqtb\_size}$}\6
\4\\{found2}: \37$\\{incr}(\|j)$;\5
$\|l\K\|j$;\6
\&{while} $\|j<\\{eqtb\_size}$ \1\&{do}\6
\&{begin} \37\&{if} $\\{eqtb}[\|j].\\{int}\I\\{eqtb}[\|j+1].\\{int}$ \1\&{then}%
\5
\&{goto} \37\\{done2};\2\6
$\\{incr}(\|j)$;\6
\&{end};\2\6
\4\\{done2}: \37$\\{dump\_int}(\|l-\|k)$;\6
\&{while} $\|k<\|l$ \1\&{do}\6
\&{begin} \37$\\{dump\_wd}(\\{eqtb}[\|k])$;\5
$\\{incr}(\|k)$;\6
\&{end};\2\6
$\|k\K\|j+1$;\5
$\\{dump\_int}(\|k-\|l)$;\6
\4\&{until}\5
$\|k>\\{eqtb\_size}$\2\par
\U section~1313.\fi

\M1317. \P$\X1317:Undump regions 1 to 6 of \\{eqtb}\X\S$\6
$\|k\K\\{active\_base}$;\6
\1\&{repeat} \37$\\{undump\_int}(\|x)$;\6
\&{if} $(\|x<1)\V(\|k+\|x>\\{eqtb\_size}+1)$ \1\&{then}\5
\&{goto} \37\\{bad\_fmt};\2\6
\&{for} $\|j\K\|k\mathrel{\&{to}}\|k+\|x-1$ \1\&{do}\5
$\\{undump\_wd}(\\{eqtb}[\|j])$;\2\6
$\|k\K\|k+\|x$;\5
$\\{undump\_int}(\|x)$;\6
\&{if} $(\|x<0)\V(\|k+\|x>\\{eqtb\_size}+1)$ \1\&{then}\5
\&{goto} \37\\{bad\_fmt};\2\6
\&{for} $\|j\K\|k\mathrel{\&{to}}\|k+\|x-1$ \1\&{do}\5
$\\{eqtb}[\|j]\K\\{eqtb}[\|k-1]$;\2\6
$\|k\K\|k+\|x$;\6
\4\&{until}\5
$\|k>\\{eqtb\_size}$\2\par
\U section~1314.\fi

\M1318. A different scheme is used to compress the hash table, since its lower
region is usually sparse. When $\\{text}(\|p)\I0$ for $\|p\L\\{hash\_used}$, we
output
two words, \|p and $\\{hash}[\|p]$. The hash table is, of course, densely
packed
for $\|p\G\\{hash\_used}$, so the remaining entries are output in a block.

\Y\P$\4\X1318:Dump the hash table\X\S$\6
$\\{dump\_int}(\\{hash\_used})$;\5
$\\{cs\_count}\K\\{frozen\_control\_sequence}-1-\\{hash\_used}$;\6
\&{for} $\|p\K\\{hash\_base}\mathrel{\&{to}}\\{hash\_used}$ \1\&{do}\6
\&{if} $\\{text}(\|p)\I0$ \1\&{then}\6
\&{begin} \37$\\{dump\_int}(\|p)$;\5
$\\{dump\_hh}(\\{hash}[\|p])$;\5
$\\{incr}(\\{cs\_count})$;\6
\&{end};\2\2\6
\&{for} $\|p\K\\{hash\_used}+1\mathrel{\&{to}}\\{undefined\_control%
\_sequence}-1$ \1\&{do}\5
$\\{dump\_hh}(\\{hash}[\|p])$;\2\6
$\\{dump\_int}(\\{cs\_count})$;\6
\\{print\_ln};\5
$\\{print\_int}(\\{cs\_count})$;\5
$\\{print}(\.{"\ multiletter\ control\ sequences"})$\par
\U section~1313.\fi

\M1319. \P$\X1319:Undump the hash table\X\S$\6
$\\{undump}(\\{hash\_base})(\\{frozen\_control\_sequence})(\\{hash\_used})$;\5
$\|p\K\\{hash\_base}-1$;\6
\1\&{repeat} \37$\\{undump}(\|p+1)(\\{hash\_used})(\|p)$;\5
$\\{undump\_hh}(\\{hash}[\|p])$;\6
\4\&{until}\5
$\|p=\\{hash\_used}$;\2\6
\&{for} $\|p\K\\{hash\_used}+1\mathrel{\&{to}}\\{undefined\_control%
\_sequence}-1$ \1\&{do}\5
$\\{undump\_hh}(\\{hash}[\|p])$;\2\6
$\\{undump\_int}(\\{cs\_count})$\par
\U section~1314.\fi

\M1320. \P$\X1320:Dump the font information\X\S$\6
$\\{dump\_int}(\\{fmem\_ptr})$;\6
\&{for} $\|k\K0\mathrel{\&{to}}\\{fmem\_ptr}-1$ \1\&{do}\5
$\\{dump\_wd}(\\{font\_info}[\|k])$;\2\6
$\\{dump\_int}(\\{font\_ptr})$;\6
\&{for} $\|k\K\\{null\_font}\mathrel{\&{to}}\\{font\_ptr}$ \1\&{do}\5
\X1322:Dump the array info for internal font number \|k\X;\2\6
\\{print\_ln};\5
$\\{print\_int}(\\{fmem\_ptr}-7)$;\5
$\\{print}(\.{"\ words\ of\ font\ info\ for\ "})$;\5
$\\{print\_int}(\\{font\_ptr}-\\{font\_base})$;\5
$\\{print}(\.{"\ preloaded\ font"})$;\6
\&{if} $\\{font\_ptr}\I\\{font\_base}+1$ \1\&{then}\5
$\\{print\_char}(\.{"s"})$\2\par
\U section~1302.\fi

\M1321. \P$\X1321:Undump the font information\X\S$\6
$\\{undump\_size}(7)(\\{font\_mem\_size})(\.{\'font\ mem\ size\'})(\\{fmem%
\_ptr})$;\6
\&{for} $\|k\K0\mathrel{\&{to}}\\{fmem\_ptr}-1$ \1\&{do}\5
$\\{undump\_wd}(\\{font\_info}[\|k])$;\2\6
$\\{undump\_size}(\\{font\_base})(\\{font\_max})(\.{\'font\ max\'})(\\{font%
\_ptr})$;\6
\&{for} $\|k\K\\{null\_font}\mathrel{\&{to}}\\{font\_ptr}$ \1\&{do}\5
\X1323:Undump the array info for internal font number \|k\X\2\par
\U section~1303.\fi

\M1322. \P$\X1322:Dump the array info for internal font number \|k\X\S$\6
\&{begin} \37$\\{dump\_qqqq}(\\{font\_check}[\|k])$;\5
$\\{dump\_int}(\\{font\_size}[\|k])$;\5
$\\{dump\_int}(\\{font\_dsize}[\|k])$;\5
$\\{dump\_int}(\\{font\_params}[\|k])$;\6
$\\{dump\_int}(\\{hyphen\_char}[\|k])$;\5
$\\{dump\_int}(\\{skew\_char}[\|k])$;\6
$\\{dump\_int}(\\{font\_name}[\|k])$;\5
$\\{dump\_int}(\\{font\_area}[\|k])$;\6
$\\{dump\_int}(\\{font\_bc}[\|k])$;\5
$\\{dump\_int}(\\{font\_ec}[\|k])$;\6
$\\{dump\_int}(\\{char\_base}[\|k])$;\5
$\\{dump\_int}(\\{width\_base}[\|k])$;\5
$\\{dump\_int}(\\{height\_base}[\|k])$;\6
$\\{dump\_int}(\\{depth\_base}[\|k])$;\5
$\\{dump\_int}(\\{italic\_base}[\|k])$;\5
$\\{dump\_int}(\\{lig\_kern\_base}[\|k])$;\6
$\\{dump\_int}(\\{kern\_base}[\|k])$;\5
$\\{dump\_int}(\\{exten\_base}[\|k])$;\5
$\\{dump\_int}(\\{param\_base}[\|k])$;\6
$\\{dump\_int}(\\{font\_glue}[\|k])$;\6
$\\{print\_nl}(\.{"\\font"})$;\5
$\\{print\_esc}(\\{font\_id\_text}(\|k))$;\5
$\\{print\_char}(\.{"="})$;\5
$\\{print\_file\_name}(\\{font\_name}[\|k],\39\\{font\_area}[\|k],\39\.{""})$;\6
\&{if} $\\{font\_size}[\|k]\I\\{font\_dsize}[\|k]$ \1\&{then}\6
\&{begin} \37$\\{print}(\.{"\ at\ "})$;\5
$\\{print\_scaled}(\\{font\_size}[\|k])$;\5
$\\{print}(\.{"pt"})$;\6
\&{end};\2\6
\&{end}\par
\U section~1320.\fi

\M1323. \P$\X1323:Undump the array info for internal font number \|k\X\S$\6
\&{begin} \37$\\{undump\_qqqq}(\\{font\_check}[\|k])$;\6
$\\{undump\_int}(\\{font\_size}[\|k])$;\5
$\\{undump\_int}(\\{font\_dsize}[\|k])$;\5
$\\{undump}(\\{min\_halfword})(\\{max\_halfword})(\\{font\_params}[\|k])$;\6
$\\{undump\_int}(\\{hyphen\_char}[\|k])$;\5
$\\{undump\_int}(\\{skew\_char}[\|k])$;\6
$\\{undump}(0)(\\{str\_ptr})(\\{font\_name}[\|k])$;\5
$\\{undump}(0)(\\{str\_ptr})(\\{font\_area}[\|k])$;\6
$\\{undump}(0)(255)(\\{font\_bc}[\|k])$;\5
$\\{undump}(0)(255)(\\{font\_ec}[\|k])$;\6
$\\{undump\_int}(\\{char\_base}[\|k])$;\5
$\\{undump\_int}(\\{width\_base}[\|k])$;\5
$\\{undump\_int}(\\{height\_base}[\|k])$;\6
$\\{undump\_int}(\\{depth\_base}[\|k])$;\5
$\\{undump\_int}(\\{italic\_base}[\|k])$;\5
$\\{undump\_int}(\\{lig\_kern\_base}[\|k])$;\6
$\\{undump\_int}(\\{kern\_base}[\|k])$;\5
$\\{undump\_int}(\\{exten\_base}[\|k])$;\5
$\\{undump\_int}(\\{param\_base}[\|k])$;\6
$\\{undump}(\\{min\_halfword})(\\{lo\_mem\_max})(\\{font\_glue}[\|k])$;\6
\&{end}\par
\U section~1321.\fi

\M1324. \P$\X1324:Dump the hyphenation tables\X\S$\6
$\\{dump\_int}(\\{hyph\_count})$;\6
\&{for} $\|k\K0\mathrel{\&{to}}\\{hyph\_size}$ \1\&{do}\6
\&{if} $\\{hyph\_word}[\|k]\I0$ \1\&{then}\6
\&{begin} \37$\\{dump\_int}(\|k)$;\5
$\\{dump\_int}(\\{hyph\_word}[\|k])$;\5
$\\{dump\_int}(\\{hyph\_list}[\|k])$;\6
\&{end};\2\2\6
$\\{dump\_int}(\\{trie\_max})$;\6
\&{for} $\|k\K0\mathrel{\&{to}}\\{trie\_max}$ \1\&{do}\5
$\\{dump\_hh}(\\{trie}[\|k])$;\2\6
$\\{dump\_int}(\\{trie\_op\_ptr})$;\6
\&{for} $\|k\K\\{min\_quarterword}+1\mathrel{\&{to}}\\{trie\_op\_ptr}$ \1\&{do}%
\6
\&{begin} \37$\\{dump\_int}(\\{hyf\_distance}[\|k])$;\5
$\\{dump\_int}(\\{hyf\_num}[\|k])$;\5
$\\{dump\_int}(\\{hyf\_next}[\|k])$;\6
\&{end};\2\6
\\{print\_ln};\5
$\\{print\_int}(\\{hyph\_count})$;\5
$\\{print}(\.{"\ hyphenation\ exception"})$;\6
\&{if} $\\{hyph\_count}\I1$ \1\&{then}\5
$\\{print\_char}(\.{"s"})$;\2\6
$\\{print\_nl}(\.{"Hyphenation\ trie\ of\ length\ "})$;\5
$\\{print\_int}(\\{trie\_max})$;\5
$\\{print}(\.{"\ has\ "})$;\5
$\\{print\_int}(\\{qo}(\\{trie\_op\_ptr}))$;\5
$\\{print}(\.{"\ op"})$;\6
\&{if} $\\{trie\_op\_ptr}\I\\{min\_quarterword}+1$ \1\&{then}\5
$\\{print\_char}(\.{"s"})$\2\par
\U section~1302.\fi

\M1325. \P$\X1325:Undump the hyphenation tables\X\S$\6
$\\{undump}(0)(\\{hyph\_size})(\\{hyph\_count})$;\6
\&{for} $\|k\K1\mathrel{\&{to}}\\{hyph\_count}$ \1\&{do}\6
\&{begin} \37$\\{undump}(0)(\\{hyph\_size})(\|j)$;\5
$\\{undump}(0)(\\{str\_ptr})(\\{hyph\_word}[\|j])$;\5
$\\{undump}(\\{min\_halfword})(\\{max\_halfword})(\\{hyph\_list}[\|j])$;\6
\&{end};\2\6
$\\{undump\_size}(0)(\\{trie\_size})(\.{\'trie\ size\'})(\\{trie\_max})$;\6
\&{for} $\|k\K0\mathrel{\&{to}}\\{trie\_max}$ \1\&{do}\5
$\\{undump\_hh}(\\{trie}[\|k])$;\2\6
$\\{undump}(\\{min\_quarterword})(\\{max\_quarterword})(\\{trie\_op\_ptr})$;\6
\&{for} $\|k\K\\{min\_quarterword}+1\mathrel{\&{to}}\\{trie\_op\_ptr}$ \1\&{do}%
\6
\&{begin} \37$\\{undump}(0)(63)(\\{hyf\_distance}[\|k])$;\C{a \\{small%
\_number}}\6
$\\{undump}(0)(63)(\\{hyf\_num}[\|k])$;\5
$\\{undump}(\\{min\_quarterword})(\\{max\_quarterword})(\\{hyf\_next}[\|k])$;\6
\&{end}\2\par
\U section~1303.\fi

\M1326. We have already printed a lot of statistics, so we set $\\{tracing%
\_stats}\K0$
to prevent them appearing again.

\Y\P$\4\X1326:Dump a couple more things and the closing check word\X\S$\6
$\\{dump\_int}(\\{interaction})$;\5
$\\{dump\_int}(\\{format\_ident})$;\5
$\\{dump\_int}(69069)$;\5
$\\{tracing\_stats}\K0$\par
\U section~1302.\fi

\M1327. \P$\X1327:Undump a couple more things and the closing check word\X\S$\6
$\\{undump}(\\{batch\_mode})(\\{error\_stop\_mode})(\\{interaction})$;\5
$\\{undump}(0)(\\{str\_ptr})(\\{format\_ident})$;\5
$\\{undump\_int}(\|x)$;\6
\&{if} $(\|x\I69069)\V\\{eof}(\\{fmt\_file})$ \1\&{then}\5
\&{goto} \37\\{bad\_fmt}\2\par
\U section~1303.\fi

\M1328. \P$\X1328:Create the \\{format\_ident}, open the format file, and
inform the user that dumping has begun\X\S$\6
$\\{selector}\K\\{new\_string}$;\5
$\\{print}(\.{"\ (preloaded\ format="})$;\5
$\\{print}(\\{job\_name})$;\5
$\\{print\_char}(\.{"\ "})$;\5
$\\{print\_int}(\\{year}\mathbin{\&{mod}}100)$;\5
$\\{print\_char}(\.{"."})$;\5
$\\{print\_int}(\\{month})$;\5
$\\{print\_char}(\.{"."})$;\5
$\\{print\_int}(\\{day})$;\5
$\\{print\_char}(\.{")"})$;\6
\&{if} $\\{interaction}=\\{batch\_mode}$ \1\&{then}\5
$\\{selector}\K\\{log\_only}$\6
\4\&{else} $\\{selector}\K\\{term\_and\_log}$;\2\6
$\\{str\_room}(1)$;\5
$\\{format\_ident}\K\\{make\_string}$;\5
$\\{pack\_job\_name}(\.{".fmt"})$;\6
\&{while} $\R\\{w\_open\_out}(\\{fmt\_file})$ \1\&{do}\5
$\\{prompt\_file\_name}(\.{"format\ file\ name"},\39\.{".fmt"})$;\2\6
$\\{print\_nl}(\.{"Beginning\ to\ dump\ on\ file\ "})$;\5
$\\{print}(\\{w\_make\_name\_string}(\\{fmt\_file}))$;\5
\\{flush\_string};\5
$\\{print\_nl}(\\{format\_ident})$\par
\U section~1302.\fi

\M1329. \P$\X1329:Close the format file\X\S$\6
$\\{w\_close}(\\{fmt\_file})$\par
\U section~1302.\fi

\N1330.  \[51] The main program.
This is it: the part of \TeX\ that executes all those procedures we have
written.

Well---almost. Let's leave space for a few more routines that we may
have forgotten.

\Y\P\X1333\*:Last-minute procedures\X\par
\fi

\M1331. We have noted that there are two versions of \TeX82. One, called %
\.{INITEX},
has to be run first; it initializes everything from scratch, without
reading a format file, and it has the capability of dumping a format file.
The other one is called `\.{VIRTEX}'; it is a ``virgin'' program that needs
to input a format file in order to get started. \.{VIRTEX} typically has
more memory capacity than \.{INITEX}, because it does not need the space
consumed by the auxiliary hyphenation tables and the numerous calls on
\\{primitive}, etc.

The \.{VIRTEX} program cannot read a format file instantaneously, of course;
the best implementations therefore allow for production versions of \TeX\ that
not only avoid the loading routine for \PASCAL\ object code, they also have
a format file pre-loaded. This is impossible to do if we stick to standard
\PASCAL, but there is a simple way to fool many systems into avoiding the
initialization, as follows.\quad(1)~We declare a global integer variable
called \\{ready\_already}. The probability is negligible that this
variable holds any particular value like 314159 when \.{VIRTEX} is first
loaded.\quad(2)~After we have read in a format file and initialized
everything, we set $\\{ready\_already}\K314159$.\quad(3)~Soon \.{VIRTEX}
will print `\.*', waiting for more input; and at this point we
interrupt the program and save its core image in some form that the
operating system can reload speedily.\quad(4)~When that core image is
activated, the program starts again at the beginning; but now
$\\{ready\_already}=314159$ and all the other global variables have
their initial values too. The former chastity has vanished!

In other words, if we allow ourselves to test the condition
$\\{ready\_already}=314159$, before \\{ready\_already} has been
assigned a value, we can avoid the lengthy initialization. Dirty tricks
rarely pay off so handsomely.

On systems that allow such preloading, the standard program called \.{TeX}
should be the one that has \.{plain} format preloaded, since that agrees
with {\sl The \TeX book}. Other versions, e.g., \.{AmSTeX}, should also
be provided for commonly used formats.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{ready\_already}: \37\\{integer};\C{a sacrifice of purity for economy}\par
\fi

\M1332. Now this is really it: \TeX\ starts and ends here.

The initial test involving \\{ready\_already} should be deleted if the
\PASCAL\ runtime system is smart enough to detect such a ``mistake.''

\Y\P\&{begin} \37\C{\\{start\_here}}\6
$\\{history}\K\\{fatal\_error\_stop}$;\C{in case we quit during initialization}%
\6
\\{t\_open\_out};\C{open the terminal for output}\6
\&{if} $\\{ready\_already}=314159$ \1\&{then}\5
\&{goto} \37\\{start\_of\_TEX};\2\6
\X14:Check the ``constant'' values for consistency\X\6
\&{if} $\\{bad}>0$ \1\&{then}\6
\&{begin} \37$\\{wterm\_ln}(\.{\'Ouch---my\ internal\ constants\ have\ been\
clobbered!\'},\39\.{\'---case\ \'},\39\\{bad}:1)$;\5
\&{goto} \37\\{final\_end};\6
\&{end};\2\6
\\{initialize};\C{set global variables to their starting values}\6
\&{init} \37\&{if} $\R\\{get\_strings\_started}$ \1\&{then}\5
\&{goto} \37\\{final\_end};\2\6
\\{init\_prim};\C{call \\{primitive} for each primitive}\6
\&{tini}\6
$\\{ready\_already}\K314159$;\6
\4\\{start\_of\_TEX}: \37\X55:Initialize the output routines\X;\6
\X1337:Get the first line of input and prepare to start\X;\6
$\\{init\_str\_ptr}\K\\{str\_ptr}$;\5
$\\{init\_pool\_ptr}\K\\{pool\_ptr}$;\6
$\\{history}\K\\{spotless}$;\C{ready to go!}\6
\\{main\_control};\C{come to life}\6
\\{final\_cleanup};\C{prepare for death}\6
\4\\{end\_of\_TEX}: \37\\{close\_files\_and\_terminate};\6
\4\\{final\_end}: \37$\\{ready\_already}\K0$;\6
\&{end}.\par
\fi

\M1333\*. Here we do whatever is needed to complete \TeX's job gracefully on
the
local operating system. The code here might come into play after a fatal
error; it must therefore consist entirely of ``safe'' operations that
cannot produce error messages. For example, it would be a mistake to call
\\{str\_room} or \\{make\_string} at this time, because a call on \\{overflow}
might lead to an infinite loop.

Actually there's one way to get error messages, via \\{prepare\_mag};
but that can't cause infinite recursion.

This program doesn't bother to close the input files that may still be open.

The new stuff at {\mc SAIL} has to do with preparing for what the user
presumably wants to do next, by typing it for him/her.

\Y\P$\4\X1333\*:Last-minute procedures\X\S$\6
\4\&{procedure}\1\  \37\\{close\_files\_and\_terminate};\6
\4\&{var} \37\|k: \37\\{integer};\C{all-purpose index}\2\6
\&{begin} \37\X1367:Finish the extensions\X;\6
\&{stat} \37\&{if} $\\{tracing\_stats}>0$ \1\&{then}\5
\X1334:Output statistics about this job\X;\2\ \&{tats}\6
\\{wake\_up\_terminal};\5
\X642\*:Finish the \.{DVI} file\X;\6
\&{if} $\\{job\_name}>0$ \1\&{then}\6
\&{begin} \37\\{wlog\_cr};\5
$\\{a\_close}(\\{log\_file})$;\5
$\\{selector}\K\\{selector}-2$;\6
\&{if} $\\{selector}=\\{term\_only}$ \1\&{then}\6
\&{begin} \37$\\{print\_nl}(\.{"Transcript\ written\ on\ "})$;\5
$\\{print}(\\{log\_name})$;\5
$\\{print\_char}(\.{"."})$;\6
\&{end};\2\6
\&{end};\2\6
\&{if} $(\\{pseudo\_typein}\I0)\W(\\{interaction}>\\{batch\_mode})$ \1\&{then}\6
\&{begin} \37$\\{write\_ln}(\\{term\_out})$;\6
\&{for} $\|k\K\\{str\_start}[\\{pseudo\_typein}]\mathrel{\&{to}}\\{str\_start}[%
\\{pseudo\_typein}+1]-1$ \1\&{do}\5
$\\{pto\_chr}(\\{xchr}[\\{str\_pool}[\|k]])$;\2\6
\&{end};\2\6
\&{end};\par
\A sections~1335\*, 1336, and~1338.
\U section~1330.\fi

\M1334. The present section goes directly to the log file instead of using
\\{print} commands, because there's no need for these strings to take
up \\{str\_pool} memory when a non-{\bf stat} version of \TeX\ is being used.

\Y\P$\4\X1334:Output statistics about this job\X\S$\6
\&{if} $\\{job\_name}>0$ \1\&{then}\C{the log file is open}\6
\&{begin} \37$\\{wlog\_ln}(\.{\'\ \'})$;\5
$\\{wlog\_ln}(\.{\'Here\ is\ how\ much\ of\ TeX\'}\.{\'s\ memory\'},\39\.{\'\
you\ used:\'})$;\5
$\\{wlog}(\.{\'\ \'},\39\\{str\_ptr}-\\{init\_str\_ptr}:1,\39\.{\'\ string%
\'})$;\6
\&{if} $\\{str\_ptr}\I\\{init\_str\_ptr}+1$ \1\&{then}\5
$\\{wlog}(\.{\'s\'})$;\2\6
$\\{wlog\_ln}(\.{\'\ out\ of\ \'},\39\\{max\_strings}-\\{init\_str\_ptr}:1)$;\6
$\\{wlog\_ln}(\.{\'\ \'},\39\\{pool\_ptr}-\\{init\_pool\_ptr}:1,\39\.{\'\
string\ characters\ out\ of\ \'},\39\\{pool\_size}-\\{init\_pool\_ptr}:1)$;\6
$\\{wlog\_ln}(\.{\'\ \'},\39\\{lo\_mem\_max}-\\{mem\_min}+\\{mem\_end}-\\{hi%
\_mem\_min}+2:1,\39\30\.{\'\ words\ of\ memory\ out\ of\ \'},\39\\{mem\_end}+1-%
\\{mem\_min}:1)$;\6
$\\{wlog\_ln}(\.{\'\ \'},\39\\{cs\_count}:1,\39\.{\'\ multiletter\ control\
sequences\ out\ of\ \'},\39\\{hash\_size}:1)$;\6
$\\{wlog}(\.{\'\ \'},\39\\{fmem\_ptr}:1,\39\.{\'\ words\ of\ font\ info\ for\ %
\'},\39\\{font\_ptr}-\\{font\_base}:1,\39\.{\'\ font\'})$;\6
\&{if} $\\{font\_ptr}\I\\{font\_base}+1$ \1\&{then}\5
$\\{wlog}(\.{\'s\'})$;\2\6
$\\{wlog\_ln}(\.{\',\ out\ of\ \'},\39\\{font\_mem\_size}:1,\39\.{\'\ for\ \'},%
\39\\{font\_max}-\\{font\_base}:1)$;\6
$\\{wlog}(\.{\'\ \'},\39\\{hyph\_count}:1,\39\.{\'\ hyphenation\ exception%
\'})$;\6
\&{if} $\\{hyph\_count}\I1$ \1\&{then}\5
$\\{wlog}(\.{\'s\'})$;\2\6
$\\{wlog\_ln}(\.{\'\ out\ of\ \'},\39\\{hyph\_size}:1)$;\6
$\\{wlog\_ln}(\.{\'\ \'},\39\\{max\_in\_stack}:1,\39\.{\'i,\'},\39\\{max\_nest%
\_stack}:1,\39\.{\'n,\'},\39\30\\{max\_param\_stack}:1,\39\.{\'p,\'},\39\30%
\\{max\_buf\_stack}+1:1,\39\.{\'b,\'},\39\30\\{max\_save\_stack}+6:1,\39\.{\'s\
stack\ positions\ out\ of\ \'},\39\30\\{stack\_size}:1,\39\.{\'i,\'},\39\\{nest%
\_size}:1,\39\.{\'n,\'},\39\\{param\_size}:1,\39\.{\'p,\'},\39\\{buf\_size}:1,%
\39\.{\'b,\'},\39\\{save\_size}:1,\39\.{\'s\'})$;\6
\&{end}\2\par
\U section~1333\*.\fi

\M1335\*. We get to the \\{final\_cleanup} routine when \.{\\end} or \.{\\dump}
has
been scanned and \\{its\_all\_over}.

\Y\P$\4\X1333\*:Last-minute procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37\\{final\_cleanup};\6
\4\&{label} \37\\{exit};\6
\4\&{var} \37\|c: \37\\{small\_number};\C{0 for \.{\\end}, 1 for \.{\\dump}}\2\6
\&{begin} \37$\|c\K\\{cur\_chr}$;\6
\&{if} $\\{job\_name}=0$ \1\&{then}\5
\\{open\_log\_file};\2\6
\&{while} $\\{cur\_level}>\\{level\_one}$ \1\&{do}\6
\&{begin} \37$\\{print\_nl}(\.{"("})$;\5
$\\{print\_esc}(\.{"end\ occurred\ when\ "})$;\6
\&{case} $\\{cur\_group}$ \1\&{of}\6
\4\\{simple\_group}: \37$\\{print\_char}(\.{"\{"})$;\6
\4\\{semi\_simple\_group}: \37$\\{print\_esc}(\.{"begingroup"})$;\6
\4\&{othercases} \37$\\{confusion}(\.{"endgroup"})$\2\6
\&{endcases};\6
$\\{print}(\.{"\ on\ line\ "})$;\5
\\{unsave};\5
$\\{decr}(\\{save\_ptr})$;\5
$\\{print\_int}(\\{saved}(0))$;\5
$\\{print}(\.{"\ was\ incomplete)"})$;\6
\&{end};\2\6
\&{while} $\\{cond\_ptr}\I\\{null}$ \1\&{do}\6
\&{begin} \37$\\{print\_nl}(\.{"("})$;\5
$\\{print\_esc}(\.{"end\ occurred\ when\ "})$;\5
$\\{print\_cmd\_chr}(\\{if\_test},\39\\{cur\_if})$;\6
\&{if} $\\{if\_line}\I0$ \1\&{then}\6
\&{begin} \37$\\{print}(\.{"\ on\ line\ "})$;\5
$\\{print\_int}(\\{if\_line})$;\6
\&{end};\2\6
$\\{print}(\.{"\ was\ incomplete)"})$;\5
$\\{if\_line}\K\\{if\_line\_field}(\\{cond\_ptr})$;\5
$\\{cur\_if}\K\\{subtype}(\\{cond\_ptr})$;\5
$\\{cond\_ptr}\K\\{link}(\\{cond\_ptr})$;\6
\&{end};\2\6
\&{if} $\\{history}\I\\{spotless}$ \1\&{then}\6
\&{if} $((\\{history}=\\{warning\_issued})\V(\\{interaction}<\\{error\_stop%
\_mode}))$ \1\&{then}\6
\&{if} $\\{selector}=\\{term\_and\_log}$ \1\&{then}\6
\&{begin} \37$\\{selector}\K\\{term\_only}$;\5
$\\{print\_nl}(\.{"(see\ the\ transcript\ file\ for\ additional\
information)"})$;\5
$\\{selector}\K\\{term\_and\_log}$;\6
\&{end};\2\2\2\6
\&{if} $\|c=1$ \1\&{then}\6
\&{begin} \37\&{init} \37\\{store\_fmt\_file};\5
\&{return};\ \&{tini}\6
$\\{print\_nl}(\.{"(\\dump\ is\ performed\ only\ by\ INITEX)"})$;\5
\&{return};\6
\&{end};\2\6
\4\\{exit}: \37\&{end};\par
\fi

\M1336. \P$\X1333\*:Last-minute procedures\X\mathrel{+}\S$\6
\&{init} \37\&{procedure}\1\  \37\\{init\_prim};\C{initialize all the
primitives}\2\6
\&{begin} \37$\\{no\_new\_control\_sequence}\K\\{false}$;\5
\X226:Put each of \TeX's primitives into the hash table\X;\6
$\\{no\_new\_control\_sequence}\K\\{true}$;\6
\&{end};\6
\&{tini}\par
\fi

\M1337. When we begin the following code, \TeX's tables may still contain
garbage;
the strings might not even be present. Thus we must proceed cautiously to get
bootstrapped in.

But when we finish this part of the program, \TeX\ is ready to call on the
\\{main\_control} routine to do its work.

\Y\P$\4\X1337:Get the first line of input and prepare to start\X\S$\6
\&{begin} \37\X331:Initialize the input routines\X;\6
\&{if} $(\\{format\_ident}=0)\V(\\{buffer}[\\{loc}]=\.{"\&"})$ \1\&{then}\6
\&{begin} \37\&{if} $\\{format\_ident}\I0$ \1\&{then}\5
\\{initialize};\C{erase preloaded format}\2\6
\&{if} $\R\\{open\_fmt\_file}$ \1\&{then}\5
\&{goto} \37\\{final\_end};\2\6
\&{if} $\R\\{load\_fmt\_file}$ \1\&{then}\6
\&{begin} \37$\\{w\_close}(\\{fmt\_file})$;\5
\&{goto} \37\\{final\_end};\6
\&{end};\2\6
$\\{w\_close}(\\{fmt\_file})$;\6
\&{while} $(\\{loc}<\\{limit})\W(\\{buffer}[\\{loc}]=\.{"\ "})$ \1\&{do}\5
$\\{incr}(\\{loc})$;\2\6
\&{end};\2\6
\&{if} $(\\{end\_line\_char}<0)\V(\\{end\_line\_char}>127)$ \1\&{then}\5
$\\{decr}(\\{limit})$\6
\4\&{else} $\\{buffer}[\\{limit}]\K\\{end\_line\_char}$;\2\6
\\{fix\_date\_and\_time};\6
\X765:Compute the magic offset\X;\6
\X75:Initialize the print \\{selector} based on \\{interaction}\X;\6
\&{if} $(\\{loc}<\\{limit})\W(\\{cat\_code}(\\{buffer}[\\{loc}])\I\\{escape})$ %
\1\&{then}\5
\\{start\_input};\C{\.{\\input} assumed}\2\6
\&{end}\par
\U section~1332.\fi

\N1338.  \[52] Debugging.
Once \TeX\ is working, it should be possible to diagnose most errors with
the \.{\\show} commands and other diagnostic features. But for the initial
stages of debugging, and for the revelation of really deep mysteries, you
can compile \TeX\ with a few more aids including the \PASCAL\ runtime
checks and its debugger. An additional routine called \\{debug\_help}
will also come into play when you type `\.D' after an error message;
\\{debug\_help} also occurs just before a fatal error causes \TeX\ to succumb.

The interface to \\{debug\_help} is primitive, but it is good enough when used
with a \PASCAL\ debugger that allows you to set breakpoints and to read
variables and change their values. After getting the prompt `\.{debug \#}', you
type either a negative number (this exits \\{debug\_help}), or zero (this
goes to a location where you can set a breakpoint, thereby entering into
dialog with the \PASCAL\ debugger), or a positive number \|m followed by
an argument \|n. The meaning of \|m and \|n will be clear from the
program below. (If $\|m=13$, there is an additional argument, \|l.)

\Y\P\D \37$\\{breakpoint}=888$\C{place where a breakpoint is desirable}\par
\Y\P$\4\X1333\*:Last-minute procedures\X\mathrel{+}\S$\6
\&{debug} \37\&{procedure}\1\  \37\\{debug\_help};\C{routine to display various
things}\6
\4\&{label} \37$\\{breakpoint},\39\\{exit}$;\6
\4\&{var} \37$\|k,\39\|l,\39\|m,\39\|n$: \37\\{integer};\2\6
\&{begin} \37\~ \1\&{loop}\6
\&{begin} \37\\{wake\_up\_terminal};\5
$\\{print\_nl}(\.{"debug\ \#\ (-1\ to\ exit):"})$;\5
\\{update\_terminal};\5
$\\{read}(\\{term\_in},\39\|m)$;\6
\&{if} $\|m<0$ \1\&{then}\5
\&{return}\6
\4\&{else} \&{if} $\|m=0$ \1\&{then}\6
\&{begin} \37\&{goto} \37\\{breakpoint};\5
\]\C{go to every label at least once}\6
\4\\{breakpoint}: \37$\|m\K0$;\5
$\B\.{\'BREAKPOINT\'}\T\]$\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{read}(\\{term\_in},\39\|n)$;\6
\&{case} $\|m$ \1\&{of}\6
\hbox{\4}\X1339:Numbered cases for \\{debug\_help}\X\6
\4\&{othercases} \37$\\{print}(\.{"?"})$\2\6
\&{endcases};\6
\&{end};\2\2\6
\&{end};\2\6
\4\\{exit}: \37\&{end};\6
\&{gubed}\par
\fi

\M1339. \P$\X1339:Numbered cases for \\{debug\_help}\X\S$\6
\41: \37$\\{print\_word}(\\{mem}[\|n])$;\C{display $\\{mem}[\|n]$ in all forms}%
\6
\42: \37$\\{print\_int}(\\{info}(\|n))$;\6
\43: \37$\\{print\_int}(\\{link}(\|n))$;\6
\44: \37$\\{print\_word}(\\{eqtb}[\|n])$;\6
\45: \37$\\{print\_word}(\\{font\_info}[\|n])$;\6
\46: \37$\\{print\_word}(\\{save\_stack}[\|n])$;\6
\47: \37$\\{show\_box}(\|n)$;\C{show a box, abbreviated by \\{show\_box\_depth}
and \\{show\_box\_breadth}}\6
\48: \37\&{begin} \37$\\{breadth\_max}\K10000$;\5
$\\{depth\_threshold}\K\\{pool\_size}-\\{pool\_ptr}-10$;\5
$\\{show\_node\_list}(\|n)$;\C{show a box in its entirety}\6
\&{end};\6
\49: \37$\\{show\_token\_list}(\|n,\39\\{null},\391000)$;\6
\410: \37$\\{print}(\|n)$;\6
\411: \37$\\{check\_mem}(\|n>0)$;\C{check wellformedness; print new busy
locations if $\|n>0$}\6
\412: \37$\\{search\_mem}(\|n)$;\C{look for pointers to \|n}\6
\413: \37\&{begin} \37$\\{read}(\\{term\_in},\39\|l)$;\5
$\\{print\_cmd\_chr}(\|n,\39\|l)$;\6
\&{end};\6
\414: \37\&{for} $\|k\K0\mathrel{\&{to}}\|n$ \1\&{do}\5
$\\{print}(\\{buffer}[\|k])$;\2\6
\415: \37\&{begin} \37$\\{font\_in\_short\_display}\K\\{null\_font}$;\5
$\\{short\_display}(\|n)$;\6
\&{end};\6
\416: \37$\\{panicking}\K\R\\{panicking}$;\par
\U section~1338.\fi

\N1340.  \[53] Extensions.
The program above includes a bunch of ``hooks'' that allow further
capabilities to be added without upsetting \TeX's basic structure.
Most of these hooks are concerned with ``whatsit'' nodes, which are
intended to be used for special purposes; whenever a new extension to
\TeX\ involves a new kind of whatsit node, a corresponding change needs
to be made to the routines below that deal with such nodes,
but it will usually be unnecessary to make many changes to the
other parts of this program.

In order to demonstrate how extensions can be made, we shall treat
`\.{\\write}', `\.{\\openout}', `\.{\\closeout}', `\.{\\immediate}, and
`\.{\\special}' as if they were extensions. These commands are actually
primitives of \TeX82, and they should appear in all implementations of the
system; but let's try to imagine that they aren't. Then the program below
illustrates how a person could add them.

Sometimes, of course, an extension will require changes to \TeX\ itself;
no system of hooks could be complete enough for all conceivable extensions.
The features associated with `\.{\\write}' are almost all confined to the
following paragraphs, but there are small parts of the \\{print\_ln} and
\\{print\_char} procedures that were introduced specifically to \.{\\write}
characters. Furthermore one of the token lists recognized by the scanner
is a \\{write\_text}; and there are a few other miscellaneous places where we
have already provided for some aspect of \.{\\write}.  The goal of a \TeX\
extender should be to minimize alterations to the standard parts of the
program, and to avoid them completely if possible. He or she should also
be quite sure that there's no easy way to accomplish the desired goals
with the standard features that \TeX\ already has. ``Think thrice before
extending,'' because that may save a lot of work, and it will also keep
incompatible extensions of \TeX\ from proliferating.

\fi

\M1341. First let's consider the format of whatsit nodes that are used to
represent
the data associated with \.{\\write} and its relatives. Recall that a whatsit
has $\\{type}=\\{whatsit\_node}$, and the \\{subtype} is supposed to
distinguish
different kinds of whatsits. Each node occupies two or more words; the
exact number is immaterial, as long as it is readily determined from the
\\{subtype} or other data.

We shall introduce four \\{subtype} values here, corresponding to the
control sequences \.{\\openout}, \.{\\write}, \.{\\closeout}, and
\.{\\special}. The second word of such whatsits has a \\{write\_stream} field
that identifies the write-stream number (0 to 15, or 16 for out-of-range and
positive, or 17 for out-of-range and negative).
In the case of \.{\\write} and \.{\\special}, there is also a field that
points to the reference count of a token list that should be sent. In the
case of \.{\\openout}, we need three words and three auxiliary subfields
to hold the string numbers for name, area, and extension.

\Y\P\D \37$\\{write\_node\_size}=2$\C{number of words in a write/whatsit node}%
\par
\P\D \37$\\{open\_node\_size}=3$\C{number of words in an open/whatsit node}\par
\P\D \37$\\{open\_node}=0$\C{\\{subtype} in whatsits that represent files to %
\.{\\openout}}\par
\P\D \37$\\{write\_node}=1$\C{\\{subtype} in whatsits that represent things to %
\.{\\write}}\par
\P\D \37$\\{close\_node}=2$\C{\\{subtype} in whatsits that represent streams to
\.{\\closeout}}\par
\P\D \37$\\{special\_node}=3$\C{\\{subtype} in whatsits that represent \.{%
\\special} things}\par
\P\D \37$\\{write\_tokens}(\#)\S\\{link}(\#+1)$\C{reference count of token list
to write}\par
\P\D \37$\\{write\_stream}(\#)\S\\{info}(\#+1)$\C{stream number (0 to 17)}\par
\P\D \37$\\{open\_name}(\#)\S\\{link}(\#+1)$\C{string number of file name to
open}\par
\P\D \37$\\{open\_area}(\#)\S\\{info}(\#+2)$\C{string number of file area for %
\\{open\_name}}\par
\P\D \37$\\{open\_ext}(\#)\S\\{link}(\#+2)$\C{string number of file extension
for \\{open\_name}}\par
\fi

\M1342. The sixteen possible \.{\\write} streams are represented by the %
\\{write\_file}
array. The \|jth file is open if and only if $\\{write\_open}[\|j]=\\{true}$.
The last
two streams are special; $\\{write\_open}[16]$ represents a stream number
greater than 15, while $\\{write\_open}[17]$ represents a negative stream
number,
and both of these variables are always \\{false}.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{write\_file}: \37\&{array} $[0\to15]$ \1\&{of}\5
\\{alpha\_file};\2\6
\4\\{write\_open}: \37\&{array} $[0\to17]$ \1\&{of}\5
\\{boolean};\2\par
\fi

\M1343. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
\&{for} $\|k\K0\mathrel{\&{to}}17$ \1\&{do}\5
$\\{write\_open}[\|k]\K\\{false}$;\2\par
\fi

\M1344. Extensions might introduce new command codes; but it's best to use
\\{extension} with a modifier, whenever possible, so that \\{main\_control}
stays the same.

\Y\P\D \37$\\{immediate\_code}=4$\C{command modifier for \.{\\immediate}}\par
\Y\P$\4\X226:Put each of \TeX's primitives into the hash table\X\mathrel{+}\S$\6
$\\{primitive}(\.{"openout"},\39\\{extension},\39\\{open\_node})$;\6
$\\{primitive}(\.{"write"},\39\\{extension},\39\\{write\_node})$;\5
$\\{write\_loc}\K\\{cur\_val}$;\6
$\\{primitive}(\.{"closeout"},\39\\{extension},\39\\{close\_node})$;\6
$\\{primitive}(\.{"special"},\39\\{extension},\39\\{special\_node})$;\6
$\\{primitive}(\.{"immediate"},\39\\{extension},\39\\{immediate\_code})$;\par
\fi

\M1345. The variable \\{write\_loc} just introduced is used to provide an
appropriate error message in case of ``runaway'' write texts.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{write\_loc}: \37\\{pointer};\C{\\{eqtb} address of \.{\\write}}\par
\fi

\M1346. \P$\X227:Cases of \\{print\_cmd\_chr} for symbolic printing of
primitives\X\mathrel{+}\S$\6
\4\\{extension}: \37\&{case} $\\{chr\_code}$ \1\&{of}\6
\4\\{open\_node}: \37$\\{print\_esc}(\.{"openout"})$;\6
\4\\{write\_node}: \37$\\{print\_esc}(\.{"write"})$;\6
\4\\{close\_node}: \37$\\{print\_esc}(\.{"closeout"})$;\6
\4\\{special\_node}: \37$\\{print\_esc}(\.{"special"})$;\6
\4\\{immediate\_code}: \37$\\{print\_esc}(\.{"immediate"})$;\6
\4\&{othercases} \37$\\{print}(\.{"[unknown\ extension!]"})$\2\6
\&{endcases};\par
\fi

\M1347. When an \\{extension} command occurs in \\{main\_control}, in any mode,
the \\{do\_extension} routine is called.

\Y\P$\4\X1347:Cases of \\{main\_control} that are for extensions to \TeX\X\S$\6
\4$\\{any\_mode}(\\{extension})$: \37\\{do\_extension};\par
\U section~1045.\fi

\M1348. \P$\X1043:Declare action procedures for use by \\{main\_control}\X%
\mathrel{+}\S$\6
\hbox{\4}\X1349:Declare procedures needed in \\{do\_extension}\X\6
\4\&{procedure}\1\  \37\\{do\_extension};\6
\4\&{var} \37$\|i,\39\|j,\39\|k$: \37\\{integer};\C{all-purpose integers}\6
$\|p,\39\|q,\39\|r$: \37\\{pointer};\C{all-purpose pointers}\2\6
\&{begin} \37\&{case} $\\{cur\_chr}$ \1\&{of}\6
\4\\{open\_node}: \37\X1351:Implement \.{\\openout}\X;\6
\4\\{write\_node}: \37\X1352:Implement \.{\\write}\X;\6
\4\\{close\_node}: \37\X1353:Implement \.{\\closeout}\X;\6
\4\\{special\_node}: \37\X1354:Implement \.{\\special}\X;\6
\4\\{immediate\_code}: \37\X1375:Implement \.{\\immediate}\X;\6
\4\&{othercases} \37$\\{confusion}(\.{"ext1"})$\2\6
\&{endcases};\6
\&{end};\par
\fi

\M1349. Here is a subroutine that creates a whatsit node having a given %
\\{subtype}
and a given number of words. It initializes only the first word of the whatsit,
and appends it to the current list.

\Y\P$\4\X1349:Declare procedures needed in \\{do\_extension}\X\S$\6
\4\&{procedure}\1\  \37$\\{new\_whatsit}(\|s:\\{small\_number};\,\35\|w:%
\\{small\_number})$;\6
\4\&{var} \37\|p: \37\\{pointer};\C{the new node}\2\6
\&{begin} \37$\|p\K\\{get\_node}(\|w)$;\5
$\\{type}(\|p)\K\\{whatsit\_node}$;\5
$\\{subtype}(\|p)\K\|s$;\5
$\\{link}(\\{tail})\K\|p$;\5
$\\{tail}\K\|p$;\6
\&{end};\par
\A section~1350.
\U section~1348.\fi

\M1350. The next subroutine uses \\{cur\_chr} to decide what sort of whatsit is
involved, and also inserts a \\{write\_stream} number.

\Y\P$\4\X1349:Declare procedures needed in \\{do\_extension}\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{new\_write\_whatsit}(\|w:\\{small\_number})$;\2\6
\&{begin} \37$\\{new\_whatsit}(\\{cur\_chr},\39\|w)$;\6
\&{if} $\|w\I\\{write\_node\_size}$ \1\&{then}\5
\\{scan\_four\_bit\_int}\6
\4\&{else} \&{begin} \37\\{scan\_int};\6
\&{if} $\\{cur\_val}<0$ \1\&{then}\5
$\\{cur\_val}\K17$\6
\4\&{else} \&{if} $\\{cur\_val}>15$ \1\&{then}\5
$\\{cur\_val}\K16$;\2\2\6
\&{end};\2\6
$\\{write\_stream}(\\{tail})\K\\{cur\_val}$;\6
\&{end};\par
\fi

\M1351. \P$\X1351:Implement \.{\\openout}\X\S$\6
\&{begin} \37$\\{new\_write\_whatsit}(\\{open\_node\_size})$;\5
\\{scan\_optional\_equals};\5
\\{scan\_file\_name};\6
$\\{open\_name}(\\{tail})\K\\{cur\_name}$;\5
$\\{open\_area}(\\{tail})\K\\{cur\_area}$;\5
$\\{open\_ext}(\\{tail})\K\\{cur\_ext}$;\6
\&{end}\par
\U section~1348.\fi

\M1352. When `\.{\\write 12\{...\}}' appears, we scan the token list `\.{\{...%
\}}'
without expanding its macros; the macros will be expanded later when this
token list is rescanned.

\Y\P$\4\X1352:Implement \.{\\write}\X\S$\6
\&{begin} \37$\|k\K\\{cur\_cs}$;\5
$\\{new\_write\_whatsit}(\\{write\_node\_size})$;\6
$\\{cur\_cs}\K\|k$;\5
$\|p\K\\{scan\_toks}(\\{false},\39\\{false})$;\5
$\\{write\_tokens}(\\{tail})\K\\{def\_ref}$;\6
\&{end}\par
\U section~1348.\fi

\M1353. \P$\X1353:Implement \.{\\closeout}\X\S$\6
\&{begin} \37$\\{new\_write\_whatsit}(\\{write\_node\_size})$;\5
$\\{write\_tokens}(\\{tail})\K\\{null}$;\6
\&{end}\par
\U section~1348.\fi

\M1354. When `\.{\\special\{...\}}' appears, we expand the macros in the token
list as in \.{\\xdef} and \.{\\mark}.

\Y\P$\4\X1354:Implement \.{\\special}\X\S$\6
\&{begin} \37$\\{new\_whatsit}(\\{special\_node},\39\\{write\_node\_size})$;\5
$\\{write\_stream}(\\{tail})\K\\{null}$;\5
$\|p\K\\{scan\_toks}(\\{false},\39\\{true})$;\5
$\\{write\_tokens}(\\{tail})\K\\{def\_ref}$;\6
\&{end}\par
\U section~1348.\fi

\M1355. Each new type of node that appears in our data structure must be
capable
of being displayed, copied, destroyed, and so on. The routines that we
need for write-oriented whatsits are somewhat like those for mark nodes;
other extensions might, of course, involve more subtlety here.

\Y\P$\4\X57:Basic printing procedures\X\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{print\_write\_whatsit}(\|s:\\{str\_number};\,\35\|p:%
\\{pointer})$;\2\6
\&{begin} \37$\\{print\_esc}(\|s)$;\6
\&{if} $\\{write\_stream}(\|p)<16$ \1\&{then}\5
$\\{print\_int}(\\{write\_stream}(\|p))$\6
\4\&{else} \&{if} $\\{write\_stream}(\|p)=16$ \1\&{then}\5
$\\{print\_char}(\.{"*"})$\6
\4\&{else} $\\{print\_char}(\.{"-"})$;\2\2\6
\&{end};\par
\fi

\M1356. \P$\X1356:Display the whatsit node \|p\X\S$\6
\&{case} $\\{subtype}(\|p)$ \1\&{of}\6
\4\\{open\_node}: \37\&{begin} \37$\\{print\_write\_whatsit}(\.{"openout"},\39%
\|p)$;\5
$\\{print\_char}(\.{"="})$;\5
$\\{print\_file\_name}(\\{open\_name}(\|p),\39\\{open\_area}(\|p),\39\\{open%
\_ext}(\|p))$;\6
\&{end};\6
\4\\{write\_node}: \37\&{begin} \37$\\{print\_write\_whatsit}(\.{"write"},\39%
\|p)$;\5
$\\{print\_mark}(\\{write\_tokens}(\|p))$;\6
\&{end};\6
\4\\{close\_node}: \37$\\{print\_write\_whatsit}(\.{"closeout"},\39\|p)$;\6
\4\\{special\_node}: \37\&{begin} \37$\\{print\_esc}(\.{"special"})$;\5
$\\{print\_mark}(\\{write\_tokens}(\|p))$;\6
\&{end};\6
\4\&{othercases} \37$\\{print}(\.{"whatsit?"})$\2\6
\&{endcases}\par
\U section~183\*.\fi

\M1357. \P$\X1357:Make a partial copy of the whatsit node \|p and make \|r
point to it; set \\{words} to the number of initial words not yet copied\X\S$\6
\&{case} $\\{subtype}(\|p)$ \1\&{of}\6
\4\\{open\_node}: \37\&{begin} \37$\|r\K\\{get\_node}(\\{open\_node\_size})$;\5
$\\{words}\K\\{open\_node\_size}$;\6
\&{end};\6
\4$\\{write\_node},\39\\{special\_node}$: \37\&{begin} \37$\|r\K\\{get\_node}(%
\\{write\_node\_size})$;\5
$\\{add\_token\_ref}(\\{write\_tokens}(\|p))$;\5
$\\{words}\K\\{write\_node\_size}$;\6
\&{end};\6
\4\\{close\_node}: \37\&{begin} \37$\|r\K\\{get\_node}(\\{small\_node\_size})$;%
\5
$\\{words}\K\\{small\_node\_size}$;\6
\&{end};\6
\4\&{othercases} \37$\\{confusion}(\.{"ext2"})$\2\6
\&{endcases}\par
\U section~206.\fi

\M1358. \P$\X1358:Wipe out the whatsit node \|p and \&{goto} \\{done}\X\S$\6
\&{begin} \37\&{case} $\\{subtype}(\|p)$ \1\&{of}\6
\4\\{open\_node}: \37$\\{free\_node}(\|p,\39\\{open\_node\_size})$;\6
\4$\\{write\_node},\39\\{special\_node}$: \37\&{begin} \37$\\{delete\_token%
\_ref}(\\{write\_tokens}(\|p))$;\5
$\\{free\_node}(\|p,\39\\{write\_node\_size})$;\5
\&{goto} \37\\{done};\6
\&{end};\6
\4\\{close\_node}: \37$\\{free\_node}(\|p,\39\\{small\_node\_size})$;\6
\4\&{othercases} \37$\\{confusion}(\.{"ext3"})$\2\6
\&{endcases};\6
\&{goto} \37\\{done};\6
\&{end}\par
\U section~202.\fi

\M1359. \P$\X1359:Incorporate a whatsit node into a vbox\X\S$\6
\\{do\_nothing}\par
\U section~669.\fi

\M1360. \P$\X1360:Incorporate a whatsit node into an hbox\X\S$\6
\\{do\_nothing}\par
\U section~651.\fi

\M1361. \P$\X1361:Let \|d be the width of the whatsit \|p\X\S$\6
$\|d\K0$\par
\U section~1147\*.\fi

\M1362. \P$\X1362:Advance \(p)past a whatsit node in the \\{line\_break} loop\X%
\S$\6
\\{do\_nothing}\par
\U section~866.\fi

\M1363. \P$\X1363:Prepare to move whatsit \|p to the current page, then %
\&{goto} \\{contribute}\X\S$\6
\&{goto} \37\\{contribute}\par
\U section~1000.\fi

\M1364. \P$\X1364:Process whatsit \|p in \\{vert\_break} loop, \&{goto} \\{not%
\_found}\X\S$\6
\&{goto} \37\\{not\_found}\par
\U section~973.\fi

\M1365. \P$\X1365:Output the whatsit node \|p in a vlist\X\S$\6
$\\{out\_what}(\|p)$\par
\U section~631.\fi

\M1366. \P$\X1366:Output the whatsit node \|p in an hlist\X\S$\6
$\\{out\_what}(\|p)$\par
\U section~622.\fi

\M1367. \P$\X1367:Finish the extensions\X\S$\6
\&{for} $\|k\K0\mathrel{\&{to}}15$ \1\&{do}\6
\&{if} $\\{write\_open}[\|k]$ \1\&{then}\5
$\\{a\_close}(\\{write\_file}[\|k])$\2\2\par
\U section~1333\*.\fi

\M1368. After all this preliminary shuffling, we come finally to the routines
that actually send out the requested data. Let's do \.{\\special} first
(it's easier).

\Y\P$\4\X1368:Declare procedures needed in \\{hlist\_out}, \\{vlist\_out}\X\S$\6
\4\&{procedure}\1\  \37$\\{special\_out}(\|p:\\{pointer})$;\6
\4\&{var} \37\\{old\_setting}: \37$0\to\\{max\_selector}$;\C{holds print %
\\{selector}}\6
\|k: \37\\{pool\_pointer};\C{index into \\{str\_pool}}\2\6
\&{begin} \37\\{synch\_h};\5
\\{synch\_v};\6
$\\{old\_setting}\K\\{selector}$;\5
$\\{selector}\K\\{new\_string}$;\5
$\\{show\_token\_list}(\\{link}(\\{write\_tokens}(\|p)),\39\\{null},\39\\{pool%
\_size}-\\{pool\_ptr})$;\5
$\\{selector}\K\\{old\_setting}$;\5
$\\{str\_room}(1)$;\6
\&{if} $\\{cur\_length}<256$ \1\&{then}\6
\&{begin} \37$\\{dvi\_out}(\\{xxx1})$;\5
$\\{dvi\_out}(\\{cur\_length})$;\6
\&{end}\6
\4\&{else} \&{begin} \37$\\{dvi\_out}(\\{xxx4})$;\5
$\\{dvi\_four}(\\{cur\_length})$;\6
\&{end};\2\6
\&{for} $\|k\K\\{str\_start}[\\{str\_ptr}]\mathrel{\&{to}}\\{pool\_ptr}-1$ \1%
\&{do}\5
$\\{dvi\_out}(\\{str\_pool}[\|k])$;\2\6
$\\{pool\_ptr}\K\\{str\_start}[\\{str\_ptr}]$;\C{erase the string}\6
\&{end};\par
\A sections~1370 and~1373.
\U section~619.\fi

\M1369. To write a token list, we must run it through \TeX's scanner, expanding
macros and \.{\\the} and \.{\\number}, etc. This might cause runaways,
if a delimited macro parameter isn't matched, and runaways would be
extremely confusing since we are calling on \TeX's scanner in the middle
of a \.{\\shipout} command. Therefore we will put a dummy control sequence as
a ``stopper,'' right after the token list. This control sequence is
artificially defined to be \.{\\outer}.

\Y\P$\4\X164:Initialize table entries (done by \.{INITEX} only)\X\mathrel{+}\S$%
\6
$\\{text}(\\{end\_write})\K\.{"endwrite"}$;\5
$\\{eq\_level}(\\{end\_write})\K\\{level\_one}$;\5
$\\{eq\_type}(\\{end\_write})\K\\{outer\_call}$;\5
$\\{equiv}(\\{end\_write})\K\\{null}$;\par
\fi

\M1370. \P$\X1368:Declare procedures needed in \\{hlist\_out}, \\{vlist\_out}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{write\_out}(\|p:\\{pointer})$;\6
\4\&{var} \37\\{old\_setting}: \37$0\to\\{max\_selector}$;\C{holds print %
\\{selector}}\6
\\{old\_mode}: \37\\{integer};\C{saved \\{mode}}\6
\|j: \37\\{small\_number};\C{write stream number}\6
$\|q,\39\|r$: \37\\{pointer};\C{temporary variables for list manipulation}\2\6
\&{begin} \37\X1371:Expand macros in the token list and make $\\{link}(\\{def%
\_ref})$ point to the result\X;\6
$\\{old\_setting}\K\\{selector}$;\5
$\|j\K\\{write\_stream}(\|p)$;\6
\&{if} $\\{write\_open}[\|j]$ \1\&{then}\5
$\\{selector}\K\|j$\6
\4\&{else} \&{begin} \37\C{write to the terminal if file isn't open}\6
\&{if} $(\|j=17)\W(\\{selector}=\\{term\_and\_log})$ \1\&{then}\5
$\\{selector}\K\\{log\_only}$;\2\6
$\\{print\_nl}(\.{""})$;\6
\&{end};\2\6
$\\{show\_token\_list}(\\{link}(\\{def\_ref}),\39\\{null},\3910000000)$;\5
\\{print\_ln};\5
$\\{flush\_list}(\\{def\_ref})$;\5
$\\{selector}\K\\{old\_setting}$;\6
\&{end};\par
\fi

\M1371. The final line of this routine is slightly subtle; at least, the author
didn't think about it until getting burnt! There is a used-up token list
on the stack, namely the one that contained \\{end\_write\_token}. (We
insert this artificial `\.{\\endwrite}' to prevent runaways, as explained
above.) If it were not removed, and if there were numerous writes on a
single page, the stack would overflow.

\Y\P\D \37$\\{end\_write\_token}\S\\{cs\_token\_flag}+\\{end\_write}$\par
\Y\P$\4\X1371:Expand macros in the token list and make $\\{link}(\\{def\_ref})$
point to the result\X\S$\6
$\|q\K\\{get\_avail}$;\5
$\\{info}(\|q)\K\\{right\_brace\_token}+\.{"\}"}$;\6
$\|r\K\\{get\_avail}$;\5
$\\{link}(\|q)\K\|r$;\5
$\\{info}(\|r)\K\\{end\_write\_token}$;\5
$\\{ins\_list}(\|q)$;\6
$\\{begin\_token\_list}(\\{write\_tokens}(\|p),\39\\{write\_text})$;\6
$\|q\K\\{get\_avail}$;\5
$\\{info}(\|q)\K\\{left\_brace\_token}+\.{"\{"}$;\5
$\\{ins\_list}(\|q)$;\C{now we're ready to scan 	`\.\{$\langle\,$token list$\,%
\rangle$\.{\} \\endwrite}'}\6
$\\{old\_mode}\K\\{mode}$;\5
$\\{mode}\K0$;\C{disable \.{\\prevdepth}, \.{\\spacefactor}, \.{\\lastskip}}\6
$\\{cur\_cs}\K\\{write\_loc}$;\5
$\|q\K\\{scan\_toks}(\\{false},\39\\{true})$;\C{expand macros, etc.}\6
\\{get\_token};\ \&{if} $\\{cur\_tok}\I\\{end\_write\_token}$ \1\&{then}\5
\X1372:Recover from an unbalanced write command\X;\2\6
$\\{mode}\K\\{old\_mode}$;\5
\\{end\_token\_list}\C{conserve stack space}\par
\U section~1370.\fi

\M1372. \P$\X1372:Recover from an unbalanced write command\X\S$\6
\&{begin} \37$\\{print\_err}(\.{"Unbalanced\ write\ command"})$;\5
$\\{help2}(\.{"On\ this\ page\ there\'s\ a\ \\write\ with\ fewer\ real\ \{\'s\
than\ \}\'s."})$\6
$(\.{"I\ can\'t\ handle\ that\ very\ well;\ good\ luck."})$;\5
\\{error};\6
\1\&{repeat} \37\\{get\_token};\6
\4\&{until}\5
$\\{cur\_tok}=\\{end\_write\_token}$;\2\6
\&{end}\par
\U section~1371.\fi

\M1373. The \\{out\_what} procedure takes care of outputting whatsit nodes for
\\{vlist\_out} and \\{hlist\_out}.

\Y\P$\4\X1368:Declare procedures needed in \\{hlist\_out}, \\{vlist\_out}\X%
\mathrel{+}\S$\6
\4\&{procedure}\1\  \37$\\{out\_what}(\|p:\\{pointer})$;\6
\4\&{var} \37\|j: \37\\{small\_number};\C{write stream number}\2\6
\&{begin} \37\&{case} $\\{subtype}(\|p)$ \1\&{of}\6
\4$\\{open\_node},\39\\{write\_node},\39\\{close\_node}$: \37\X1374:Do some
work that has been queued up for \.{\\write}\X;\6
\4\\{special\_node}: \37$\\{special\_out}(\|p)$;\6
\4\&{othercases} \37$\\{confusion}(\.{"ext4"})$\2\6
\&{endcases};\6
\&{end};\par
\fi

\M1374. We don't implement \.{\\write} inside of leaders. (The reason is that
the number of times a leader box appears might be different in different
implementations, due to machine-dependent rounding in the glue calculations.)

\Y\P$\4\X1374:Do some work that has been queued up for \.{\\write}\X\S$\6
\&{if} $\R\\{doing\_leaders}$ \1\&{then}\6
\&{begin} \37$\|j\K\\{write\_stream}(\|p)$;\6
\&{if} $\\{subtype}(\|p)=\\{write\_node}$ \1\&{then}\5
$\\{write\_out}(\|p)$\6
\4\&{else} \&{begin} \37\&{if} $\\{write\_open}[\|j]$ \1\&{then}\5
$\\{a\_close}(\\{write\_file}[\|j])$;\2\6
\&{if} $\\{subtype}(\|p)=\\{close\_node}$ \1\&{then}\5
$\\{write\_open}[\|j]\K\\{false}$\6
\4\&{else} \&{if} $\|j<16$ \1\&{then}\6
\&{begin} \37$\\{cur\_name}\K\\{open\_name}(\|p)$;\5
$\\{cur\_area}\K\\{open\_area}(\|p)$;\5
$\\{cur\_ext}\K\\{open\_ext}(\|p)$;\6
\&{if} $\\{cur\_ext}=\.{""}$ \1\&{then}\5
$\\{cur\_ext}\K\.{".tex"}$;\2\6
\\{pack\_cur\_name};\6
\&{while} $\R\\{a\_open\_out}(\\{write\_file}[\|j])$ \1\&{do}\5
$\\{prompt\_file\_name}(\.{"output\ file\ name"},\39\.{".tex"})$;\2\6
$\\{write\_open}[\|j]\K\\{true}$;\6
\&{end};\2\2\6
\&{end};\2\6
\&{end}\2\par
\U section~1373.\fi

\M1375. The presence of `\.{\\immediate}' causes the \\{do\_extension}
procedure
to descend to one level of recursion. Nothing happens unless \.{\\immediate}
is followed by `\.{\\openout}', `\.{\\write}', or `\.{\\closeout}'.

\Y\P$\4\X1375:Implement \.{\\immediate}\X\S$\6
\&{begin} \37\\{get\_x\_token};\6
\&{if} $(\\{cur\_cmd}=\\{extension})\W(\\{cur\_chr}\L\\{close\_node})$ \1%
\&{then}\6
\&{begin} \37$\|p\K\\{tail}$;\5
\\{do\_extension};\C{append a whatsit node}\6
$\\{out\_what}(\\{tail})$;\C{do the action immediately}\6
$\\{flush\_node\_list}(\\{tail})$;\5
$\\{tail}\K\|p$;\5
$\\{link}(\|p)\K\\{null}$;\6
\&{end}\6
\4\&{else} \\{back\_input};\2\6
\&{end}\par
\U section~1348.\fi

\N1376\*.  \[54] System-dependent changes.
Here are the remaining things needed to make the implementation
complete at {\mc SAIL}.

\fi

\M1377\*. The \\{pseudo\_typein} variable is set nonzero if the \\{error}
routine
uses the `\.E' option to exit and edit.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{pseudo\_typein}: \37\\{str\_number};\par
\fi

\M1378\*. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{pseudo\_typein}\K0$;\5
$\\{page}\K0$;\par
\fi

\M1379\*. The \\{mem} array is declared after the other global variables, so
that our friendly \PASCAL\ will compile things correctly.

\Y\P$\4\X13:Global variables\X\mathrel{+}\S$\6
\4\\{mem}: \37\&{array} $[\\{mem\_min}\to\\{mem\_max}]$ \1\&{of}\5
\\{memory\_word};\C{the big dynamic storage area}\2\6
\4\\{trace\_depth}: \37\\{integer};\par
\fi

\M1380\*. \P$\X21:Set initial values of key variables\X\mathrel{+}\S$\6
$\\{trace\_depth}\K0$;\par
\fi

\N1381\*.  \[55] Index.
Here is where you can find all uses of each identifier in the program,
with underlined entries pointing to where the identifier was defined.
If the identifier is only one letter long, however, you get to see only
the underlined entries. All references are to section numbers instead of
page numbers.

This index also lists error messages and other aspects of the program
that you might want to look up some day. For example, the entry
for ``system dependencies'' lists all sections that should receive
special attention from people who are installing \TeX\ in a new
operating environment. A list of various things that can't happen appears
under ``this can't happen''. Approximately 40 sections are listed under
``inner loop''; these account for about 60\% of \TeX's running time,
exclusive of input and output.
\fi


\ch 2\*, 7\*, 8\*, 9\*, 11\*, 12\*, 23\*, 27\*, 30\*, 31\*, 32\*, 33\*, 34\*,
37\*, 49\*, 71\*, 84\*, 110\*, 112\*, 116\*, 134\*, 174\*, 176\*, 183\*, 208\*,
209\*, 232\*, 241\*, 265\*, 266\*, 304\*, 313\*, 328\*, 329\*, 336\*, 341\*,
363\*, 366\*, 407\*, 435\*, 440\*, 448\*, 485\*, 493\*, 494\*, 513\*, 514\*,
516\*, 517\*, 518\*, 519\*, 520\*, 521\*, 523\*, 525\*, 530\*, 538\*, 582\*,
594\*, 595\*, 597\*, 620\*, 642\*, 654\*, 663\*, 675\*, 841\*, 842\*, 867\*,
871\*, 896\*, 899\*, 1046\*, 1063\*, 1068\*, 1090\*, 1122\*, 1124\*, 1125\*,
1147\*, 1333\*, 1335\*, 1376\*, 1377\*, 1378\*, 1379\*, 1380\*, 1381\*.
\inx
\:\.{**}, 37\*, 534.
\:\.{*\relax}, 174\*, 176\*, 178, 313\*, 360, 856, 1006, 1355.
\:\.{->}, 294.
\:\.{???}, 59, 60.
\:\.{?\relax}, 83.
\:\.{\AT!}, 856.
\:\.{\AT!\AT!}, 846.
\:\|{a}, \[47], \[102], \[218], \[518\*], \[519\*], \[523\*], \[560], \[597\*],
\[691], \[722], \[738], \[752], \[1123], \[1194], \[1211], \[1236], \[1257].
\:\.{A <box> was supposed to...}, 1084.
\:\\{a\_close}, \[28], 51, 329\*, 485\*, 486, 1275, 1333\*, 1367, 1374.
\:\\{a\_leaders}, \[149], 189, 625, 627, 634, 636, 656, 671, 1071, 1072, 1073,
1078, 1148.
\:\\{a\_make\_name\_string}, \[525\*], 534, 537.
\:\\{a\_open\_in}, \[27\*], 51, 537, 1275.
\:\\{a\_open\_out}, \[27\*], 534, 1374.
\:\\{A\_token}, \[445].
\:\\{abort}, \[560], 563, 564, 565, 568, 569, 570, 571, 573, 575.
\:\\{above}, \[208\*], 1046\*, 1178, 1179, 1180.
\:\9{above\_}{\.{\\above} primitive}, \[1178].
\:\\{above\_code}, \[1178], 1179, 1182, 1183.
\:\\{above\_display\_short\_skip}, \[224], 814.
\:\9{above\_display\_short\_skip\_}{\.{\\abovedisplayshortskip} primitive}, %
\[226].
\:\\{above\_display\_short\_skip\_code}, \[224], 225, 226, 1203.
\:\\{above\_display\_skip}, \[224], 814.
\:\9{above\_display\_skip\_}{\.{\\abovedisplayskip} primitive}, \[226].
\:\\{above\_display\_skip\_code}, \[224], 225, 226, 1203, 1206.
\:\9{above\_with\_delims\_}{\.{\\abovewithdelims} primitive}, \[1178].
\:\\{abs}, 66, 186, 211, 218, 219, 418, 422, 448\*, 501, 610, 663\*, 675\*,
718, 737, 757, 758, 759, 831, 836, 849, 859, 944, 947, 1029, 1030, 1056, 1076,
1078, 1080, 1083, 1093, 1110, 1120, 1127, 1149, 1243, 1244.
\:\\{absorbing}, \[305], 306, 339, 473.
\:\\{acc\_kern}, \[155], 191, 837, 842\*, 879, 1125\*.
\:\\{accent}, \[208\*], 265\*, 266\*, 1090\*, 1122\*, 1164, 1165.
\:\9{accent\_}{\.{\\accent} primitive}, \[265\*].
\:\\{accent\_chr}, \[687], 696, 738, 1165.
\:\\{accent\_noad}, \[687], 690, 696, 698, 733, 761, 1165, 1186.
\:\\{accent\_noad\_size}, \[687], 698, 761, 1165.
\:\\{act\_width}, \[866], 867\*, 869, 870.
\:{action procedure}, \[1029].
\:\\{active}, \[162], 819, 829, 843, 854, 860, 861, 863, 864, 865, 873, 874,
875.
\:\\{active\_base}, 220, \[222], 252, 253, 255, 262, 263, 353, 442, 506, 1152,
1257, 1289, 1315, 1317.
\:\\{active\_char}, \[207], 344, 506.
\:\\{active\_height}, \[970], 975, 976.
\:\\{active\_node\_size}, \[819], 845, 860, 864, 865.
\:\\{active\_width}, \[823], 824, 829, 843, 861, 864, 866, 869, 970.
\:\\{actual\_looseness}, \[872], 873, 875.
\:\\{add\_delims\_to}, \[347].
\:\\{add\_glue\_ref}, \[203], 206, 430, 802, 881, 996, 1100, 1229.
\:\\{add\_token\_ref}, \[203], 206, 323, 979, 1012, 1016, 1221, 1227, 1357.
\:\\{additional}, \[644], 645, 657, 672.
\:\\{adj\_demerits}, \[236], 836, 859.
\:\9{adj\_demerits\_}{\.{\\adjdemerits} primitive}, \[238].
\:\\{adj\_demerits\_code}, \[236], 237, 238.
\:\\{adjust}, \[576].
\:\\{adjust\_head}, \[162], 888, 889, 1076, 1085, 1199, 1204.
\:\\{adjust\_node}, \[142], 148, 175, 183\*, 202, 206, 647, 651, 655, 730, 761,
866, 899\*, 1100.
\:\\{adjust\_ptr}, \[142], 197, 202, 206, 655, 1100.
\:\\{adjust\_tail}, \[647], 648, 649, 651, 655, 796, 888, 889, 1076, 1085, 1199.
\:\\{adjusted\_hbox\_group}, \[269], 1062, 1083, 1085.
\:\\{advance}, \[209\*], 265\*, 266\*, 1210, 1235, 1236, 1238.
\:\9{advance\_}{\.{\\advance} primitive}, \[265\*].
\:\\{after}, \[147], 866, 1196.
\:\\{after\_assignment}, \[208\*], 265\*, 266\*, 1268.
\:\9{after\_assignment\_}{\.{\\afterassignment} primitive}, \[265\*].
\:\\{after\_group}, \[208\*], 265\*, 266\*, 1271.
\:\9{after\_group\_}{\.{\\aftergroup} primitive}, \[265\*].
\:\\{after\_math}, 1193, \[1194].
\:\\{after\_token}, \[1266], 1267, 1268, 1269.
\:\\{aire}, \[560], 561, 563, 576.
\:\\{align\_error}, 1126, \[1127].
\:\\{align\_group}, \[269], 768, 774, 791, 800, 1131, 1132.
\:\\{align\_head}, \[162], 770, 777.
\:\\{align\_peek}, 773, 774, \[785], 799, 1048, 1133.
\:\\{align\_ptr}, \[770], 771, 772.
\:\\{align\_stack\_node\_size}, \[770], 772.
\:\\{align\_state}, 88, \[309], 324, 325, 331, 339, 342, 347, 357, 394, 395,
396, 403, 442, 475, 482, 486, 770, 771, 772, 774, 777, 783, 784, 785, 788, 789,
791, 1069, 1094, 1126, 1127.
\:\\{aligning}, \[305], 306, 339, 777, 789.
\:{alignment of rules with characters}, 589.
\:\\{alpha}, \[560], 571, 572.
\:\\{alpha\_file}, \[25], 27\*, 28, 31\*, 50, 54, 304\*, 480, 525\*, 1342.
\:\\{alpha\_token}, \[438], 440\*.
\:\\{alter\_aux}, 1242, \[1243].
\:\\{alter\_box\_dimen}, 1242, \[1247].
\:\\{alter\_integer}, 1242, \[1246].
\:\\{alter\_page\_so\_far}, 1242, \[1245].
\:\\{alter\_prev\_graf}, 1242, \[1244].
\:\.{Ambiguous...}, 1183.
\:{Amble, Ole}, 925.
\:\.{AmSTeX}, 1331.
\:\\{any\_mode}, \[1045], 1048, 1057, 1063\*, 1067, 1073, 1097, 1102, 1104,
1126, 1134, 1210, 1268, 1271, 1274, 1276, 1285, 1290, 1347.
\:\\{any\_state\_plus}, \[344], 345, 347.
\:\\{app\_space}, 1030, \[1043].
\:\\{append\_char}, \[42], 48, 52, 58, 180, 195, 260, 516\*, 525\*, 692, 695,
939.
\:\\{append\_choices}, 1171, \[1172].
\:\\{append\_discretionary}, 1116, \[1117].
\:\\{append\_glue}, 1057, \[1060], 1078.
\:\\{append\_italic\_correction}, 1112, \[1113].
\:\\{append\_kern}, 1057, \[1061].
\:\\{append\_normal\_space}, \[1030].
\:\\{append\_penalty}, 1102, \[1103].
\:\\{append\_to\_name}, \[519\*], 523\*.
\:\\{append\_to\_vlist}, \[679], 799, 888, 1076, 1203, 1204, 1205.
\:\\{area\_delimiter}, \[513\*], 515, 516\*, 517\*.
\:\.{Argument of \\x has...}, 395.
\:\\{arith\_error}, \[104], 105, 106, 107, 448\*, 453, 460, 1236.
\:\.{Arithmetic overflow}, 1236.
\:\\{artificial\_badness}, \[830], 851, 854, 856.
\:\\{ary\_out}, 27\*, \[597\*].
\:{ASCII code}, 17, 503.
\:\\{ASCII\_code}, \[18], 19, 20, 29, 30\*, 31\*, 39, 42, 54, 58, 60, 82, 292,
389, 516\*, 519\*, 523\*, 692, 892, 912, 945, 953, 959, 960.
\:\\{assign\_dimen}, \[209\*], 248, 249, 413, 1210, 1224, 1228.
\:\\{assign\_font\_dimen}, \[209\*], 265\*, 266\*, 413, 1210, 1253.
\:\\{assign\_font\_int}, \[209\*], 413, 1210, 1253, 1254, 1255.
\:\\{assign\_glue}, \[209\*], 226, 227, 413, 782, 1210, 1224, 1228.
\:\\{assign\_int}, \[209\*], 238, 239, 413, 1210, 1222, 1224, 1228, 1237.
\:\\{assign\_mu\_glue}, \[209\*], 226, 227, 413, 1210, 1222, 1224, 1228, 1237.
\:\\{assign\_toks}, \[209\*], 230, 231, 233, 323, 413, 415, 1210, 1224, 1226,
1227.
\:\.{at}, 1258.
\:\9{atop\_}{\.{\\atop} primitive}, \[1178].
\:\\{atop\_code}, \[1178], 1179, 1182.
\:\9{atop\_with\_delims\_}{\.{\\atopwithdelims} primitive}, \[1178].
\:\\{attach\_fraction}, \[448\*], 453, 454, 456.
\:\\{attach\_sign}, \[448\*], 449, 455.
\:\\{auto\_breaking}, \[862], 863, 866, 868.
\:\\{aux}, 212, \[213], 216, 418, 786, 812.
\:\\{aux\_buf}, \[30\*], 31\*, 485\*, 538\*.
\:\\{aux\_field}, \[212], 213, 218, 775.
\:\\{avail}, \[118], 120, 121, 122, 123, 164, 168, 1311, 1312.
\:\.{AVAIL list clobbered...}, 168.
\:\\{awful\_bad}, \[833], 834, 835, 836, 854, 874, 970, 974, 975, 987, 1005,
1006, 1007.
\:\\{axis\_height}, \[700], 706, 736, 746, 747, 749, 762.
\:\|{b}, \[498], \[523\*], \[560], \[597\*], \[649], \[668], \[679], \[705], %
\[706], \[709], \[711], \[715], \[830], \[970], \[994], \[1198], \[1247], %
\[1288].
\:\\{b\_close}, \[28], 560, 642\*.
\:\\{b\_make\_name\_string}, \[525\*], 532.
\:\\{b\_open\_in}, \[27\*], 563.
\:\\{b\_open\_out}, \[27\*], 532.
\:\\{back\_error}, \[327], 373, 396, 403, 415, 442, 446, 476, 479, 503, 577,
783, 1078, 1084, 1161, 1197, 1207, 1212.
\:\\{back\_input}, 281, \[325], 326, 327, 368, 369, 372, 375, 379, 395, 405,
407\*, 415, 443, 444, 448\*, 452, 455, 461, 526, 788, 1031, 1047, 1054, 1064,
1090\*, 1095, 1124\*, 1127, 1132, 1138, 1150, 1152, 1153, 1215, 1221, 1226,
1269, 1375.
\:\\{back\_list}, \[323], 325, 337, 407\*, 1288.
\:\\{backed\_up}, \[307], 311, 312, 314, 323, 324, 325.
\:\\{background}, \[823], 824, 827, 837, 864.
\:\\{backup\_backup}, \[366\*].
\:\\{backup\_head}, \[162], 366\*, 407\*.
\:\.{BAD}, 293, 294.
\:\\{bad}, \[13], 14, 111, 290, 522, 1249, 1332.
\:\.{Bad \\patterns}, 961.
\:\.{Bad \\prevgraf}, 1244.
\:\.{Bad character code}, 432, 435\*.
\:\.{Bad delimiter code}, 437.
\:\.{Bad flag...}, 170.
\:\.{Bad link...}, 182.
\:\.{Bad math code}, 436.
\:\.{Bad number}, 434.
\:\.{Bad register code}, 433.
\:\.{Bad space factor}, 1243.
\:\\{bad\_fmt}, \[1303], 1306, 1308, 1312, 1317, 1327.
\:\\{bad\_pool}, \[51], 52, 53.
\:\\{bad\_tfm}, \[560].
\:\\{badness}, \[108], 660, 667, 674, 678, 828, 852, 853, 975, 1007.
\:\\{banner}, \[2\*], 61, 536, 1299.
\:\\{base\_line}, \[619], 623, 624, 628.
\:\\{base\_ptr}, 84\*, 85, \[310], 311, 312, 313\*.
\:\\{baseline\_skip}, \[224], 247, 679.
\:\9{baseline\_skip\_}{\.{\\baselineskip} primitive}, \[226].
\:\\{baseline\_skip\_code}, 149, \[224], 225, 226, 679.
\:\\{batch\_mode}, \[73], 75, 86, 90, 92, 93, 1262, 1263, 1327, 1328, 1333\*.
\:\9{batch\_mode\_}{\.{\\batchmode} primitive}, \[1262].
\:\\{bc}, 540, 541, 543, \[560], 565, 566, 570, 576.
\:\\{before}, \[147], 192, 1196.
\:\&{begin}, 7\*, 8\*.
\:\\{begin\_box}, 1073, \[1079], 1084.
\:\\{begin\_diagnostic}, 76, \[245], 284, 299, 323, 400, 401, 502, 509, 581,
638, 641, 663\*, 675\*, 863, 987, 992, 1006, 1011, 1121, 1293, 1296.
\:\\{begin\_file\_reading}, 78, 87, \[328\*], 483, 537.
\:\\{begin\_group}, \[208\*], 265\*, 266\*, 1063\*.
\:\9{begin\_group\_}{\.{\\begingroup} primitive}, \[265\*].
\:\\{begin\_insert\_or\_adjust}, 1097, \[1099].
\:\\{begin\_name}, 512, \[515], 526, 527, 531.
\:\\{begin\_pseudoprint}, \[316], 318, 319.
\:\\{begin\_token\_list}, \[323], 359, 386, 390, 774, 788, 789, 799, 1025,
1030, 1083, 1091, 1139, 1145, 1167, 1371.
\:\.{Beginning to dump...}, 1328.
\:\\{below\_display\_short\_skip}, \[224].
\:\9{below\_display\_short\_skip\_}{\.{\\belowdisplayshortskip} primitive}, %
\[226].
\:\\{below\_display\_short\_skip\_code}, \[224], 225, 226, 1203.
\:\\{below\_display\_skip}, \[224].
\:\9{below\_display\_skip\_}{\.{\\belowdisplayskip} primitive}, \[226].
\:\\{below\_display\_skip\_code}, \[224], 225, 226, 1203, 1206.
\:\\{best\_bet}, \[872], 874, 875, 877, 878.
\:\\{best\_height\_plus\_depth}, \[971], 974, 1010, 1011.
\:\\{best\_ins\_ptr}, \[981], 1005, 1009, 1018, 1020, 1021.
\:\\{best\_line}, \[872], 874, 875, 877, 890.
\:\\{best\_page\_break}, \[980], 1005, 1013, 1014.
\:\\{best\_pl\_line}, \[833], 845, 855.
\:\\{best\_place}, \[833], 845, 855, \[970], 974, 980.
\:\\{best\_size}, \[980], 1005, 1017.
\:\\{beta}, \[560], 571, 572.
\:\\{big\_op\_spacing1}, \[701], 751.
\:\\{big\_op\_spacing2}, \[701], 751.
\:\\{big\_op\_spacing3}, \[701], 751.
\:\\{big\_op\_spacing4}, \[701], 751.
\:\\{big\_op\_spacing5}, \[701], 751.
\:\\{big\_switch}, 209\*, 236, 994, 1029, \[1030], 1031, 1033, 1041.
\:{BigEndian order}, \[540].
\:\\{bin\_noad}, \[682], 690, 696, 698, 728, 729, 761, 1156, 1157.
\:\\{bin\_op\_penalty}, \[236], 761.
\:\9{bin\_op\_penalty\_}{\.{\\binoppenalty} primitive}, \[238].
\:\\{bin\_op\_penalty\_code}, \[236], 237, 238.
\:\\{blank\_line}, \[245].
\:\\{boolean}, 27\*, 31\*, 34\*, 37\*, 45, 46, 47, 76, 79, 96, 104, 106, 107,
165, 167, 241\*, 245, 256, 361, 407\*, 413, 440\*, 448\*, 461, 473, 498, 516\*,
524, 527, 549, 560, 578, 592, 619, 629, 706, 719, 726, 791, 825, 828, 829, 830,
862, 877, 950, 960, 989, 1012, 1032, 1051, 1054, 1091, 1160, 1194, 1211, 1281,
1303, 1342.
\:\\{bop}, 583, 585, \[586], 588, 590, 592, 638, 640.
\:{Bosshard, Hans Rudolf}, 458.
\:\\{bot}, \[546].
\:\\{bot\_mark}, \[382], 383, 1012, 1016.
\:\9{bot\_mark\_}{\.{\\botmark} primitive}, \[384].
\:\\{bot\_mark\_code}, \[382], 384, 385.
\:\\{bottom\_level}, \[269], 272, 281, 1064, 1068\*.
\:{bowels}, 592.
\:\\{box}, \[230], 232\*, 420, 505, 977, 992, 993, 1009, 1015, 1017, 1018,
1021, 1023, 1028, 1079, 1110, 1247, 1296.
\:\9{box\_}{\.{\\box} primitive}, \[1071].
\:\\{box\_base}, \[230], 232\*, 233, 255, 1077.
\:\\{box\_code}, \[1071], 1072, 1079, 1107, 1110.
\:\\{box\_end}, \[1075], 1079, 1084, 1086.
\:\\{box\_error}, \[992], 993, 1015, 1028.
\:\\{box\_flag}, \[1071], 1075, 1077, 1083, 1241.
\:\\{box\_max\_depth}, \[247], 1086.
\:\9{box\_max\_depth\_}{\.{\\boxmaxdepth} primitive}, \[248].
\:\\{box\_max\_depth\_code}, \[247], 248.
\:\\{box\_node\_size}, \[135], 136, 202, 206, 649, 668, 715, 727, 751, 756,
977, 1021, 1100, 1110, 1201.
\:\\{box\_ref}, \[210], 232\*, 275, 1077.
\:\\{box\_there}, \[980], 987, 1000, 1001.
\:\9{box255}{\.{\\box255 is not void}}, 1015.
\:\.{bp}, 458.
\:{brain}, 1029.
\:\\{breadth\_max}, \[181], 182, 198, 233, 236, 1339.
\:\\{break}, 34\*.
\:\\{break\_in}, 34\*.
\:\\{break\_node}, \[819], 845, 855, 856, 864, 877, 878.
\:\\{break\_penalty}, \[208\*], 265\*, 266\*, 1102.
\:\\{break\_type}, \[829], 837, 845, 846, 859.
\:\\{break\_width}, \[823], 824, 837, 838, 840, 841\*, 842\*, 843, 844, 879.
\:\\{breakpoint}, \[1338].
\:\\{broken\_ins}, \[981], 986, 1010, 1021.
\:\\{broken\_penalty}, \[236], 890.
\:\9{broken\_penalty\_}{\.{\\brokenpenalty} primitive}, \[238].
\:\\{broken\_penalty\_code}, \[236], 237, 238.
\:\\{broken\_ptr}, \[981], 1010, 1021.
\:\\{buf\_size}, \[11\*], 30\*, 31\*, 71\*, 111, 315, 328\*, 331, 341\*, 363\*,
366\*, 374, 524, 530\*, 534, 1334.
\:\\{buffer}, \[30\*], 31\*, 36, 37\*, 45, 71\*, 83, 87, 88, 259, 260, 261,
264, 302, 303, 315, 318, 331, 341\*, 343, 352, 354, 355, 356, 360, 362, 363\*,
366\*, 374, 483, 484, 485\*, 523\*, 524, 530\*, 531, 534, 538\*, 1337, 1339.
\:\\{build\_choices}, 1173, \[1174].
\:\\{build\_discretionary}, 1118, \[1119].
\:\\{build\_page}, 800, 812, 988, \[994], 1026, 1054, 1060, 1076, 1091, 1094,
1100, 1103, 1145, 1200.
\:\\{bypass\_eoln}, \[31\*].
\:\\{bypass\_xchar}, \[134\*], 183\*, 654\*, 842\*, 867\*, 871\*, 1147\*.
\:\\{byte\_file}, \[25], 27\*, 28, 525\*, 532, 539.
\:\\{b0}, 110\*, \[113], 114, 133, 221, 268, 545, 546, 550, 554, 556, 564, 602,
683, 685, 921, 966, 1309, 1310.
\:\\{b1}, 110\*, \[113], 114, 133, 221, 268, 545, 546, 554, 556, 564, 602, 683,
685, 921, 966, 1309, 1310.
\:\\{b2}, 110\*, \[113], 114, 545, 546, 554, 556, 564, 602, 683, 685, 1309,
1310.
\:\\{b3}, 110\*, \[113], 114, 545, 546, 556, 564, 602, 683, 685, 1309, 1310.
\:\|{c}, \[47], \[63], \[68], \[82], \[144], \[264], \[274], \[292], \[470], %
\[516\*], \[519\*], \[523\*], \[560], \[581], \[582\*], \[592], \[597\*], %
\[692], \[694], \[706], \[709], \[711], \[712], \[738], \[893], \[906], \[912],
\[953], \[959], \[960], \[994], \[1012], \[1032], \[1086], \[1110], \[1117], %
\[1136], \[1151], \[1155], \[1181], \[1243], \[1245], \[1246], \[1247], %
\[1275], \[1279], \[1288], \[1335\*].
\:\\{c\_leaders}, \[149], 190, 627, 636, 1071, 1072.
\:\9{c\_leaders\_}{\.{\\cleaders} primitive}, \[1071].
\:\\{call}, \[210], 223, 275, 296, 366\*, 380, 387, 395, 396, 507, 1218, 1221,
1225, 1226, 1227, 1295.
\:\\{call\_i}, 241\*.
\:\.{cannot \\read}, 484.
\:\\{car\_ret}, \[207], 232\*, 342, 347, 777, 780, 781, 783, 784, 785, 788,
1126.
\:\\{carriage\_return}, \[22], 27\*, 49\*, 84\*, 207, 232\*, 240.
\:\\{case\_shift}, \[208\*], 1285, 1286, 1287.
\:\\{cat}, \[341\*], 354, 355, 356.
\:\\{cat\_code}, \[230], 232\*, 236, 262, 341\*, 343, 354, 355, 356, 1337.
\:\9{cat\_code\_}{\.{\\catcode} primitive}, \[1230].
\:\\{cat\_code\_base}, \[230], 232\*, 233, 235, 1230, 1231, 1233.
\:\.{cc}, 458.
\:\\{cclsw}, \[37\*].
\:\\{change\_if\_limit}, \[497], 498, 509.
\:\\{char}, 19, 26, 37\*, 520\*, 534.
\:\9{char\_}{\.{\\char} primitive}, \[265\*].
\:\\{char\_base}, \[550], 552, 554, 566, 570, 576, 1322, 1323.
\:\\{char\_box}, \[709], 710, 711, 738.
\:\9{char\_def\_}{\.{\\chardef} primitive}, \[1222].
\:\\{char\_def\_code}, \[1222], 1223, 1224.
\:\\{char\_depth}, \[554], 654\*, 708, 709, 712.
\:\\{char\_depth\_end}, \[554].
\:\\{char\_exists}, \[554], 582\*, 708, 722, 738, 755, 1035.
\:\\{char\_given}, \[208\*], 413, 935, 1030, 1036, 1090\*, 1124\*, 1151, 1154,
1222, 1223, 1224.
\:\\{char\_height}, \[554], 654\*, 708, 709, 712, 1125\*.
\:\\{char\_height\_end}, \[554].
\:\\{char\_info}, 543, 550, \[554], 555, 570, 582\*, 620\*, 654\*, 708, 709,
712, 714, 715, 722, 724, 738, 740, 749, 841\*, 842\*, 866, 867\*, 871\*, 908,
1035, 1113, 1123, 1125\*, 1147\*.
\:\\{char\_info\_end}, \[554].
\:\\{char\_info\_word}, 541, \[543], 544.
\:\\{char\_italic}, \[554], 709, 714, 749, 755, 1113.
\:\\{char\_italic\_end}, \[554].
\:\\{char\_kern}, \[557], 741, 753, 908, 1038.
\:\\{char\_kern\_end}, \[557].
\:\\{char\_node}, \[134\*], 143, 145, 162, 176\*, 548, 592, 620\*, 649, 752,
881, 1029, 1032, 1113, 1138.
\:\\{char\_num}, \[208\*], 265\*, 266\*, 935, 1030, 1036, 1090\*, 1124\*, 1151,
1154.
\:\\{char\_tag}, \[554], 570, 708, 710, 740, 741, 749, 752, 908, 1036.
\:\\{char\_warning}, \[581], 582\*, 722, 1033, 1035.
\:\\{char\_width}, \[554], 620\*, 654\*, 709, 714, 715, 740, 841\*, 842\*, 866,
867\*, 871\*, 1123, 1125\*, 1147\*.
\:\\{char\_width\_end}, \[554].
\:\\{character}, \[134\*], 143, 144, 174\*, 176\*, 206, 582\*, 620\*, 654\*,
681, 682, 683, 687, 691, 709, 715, 722, 724, 749, 752, 753, 841\*, 842\*, 866,
867\*, 871\*, 896\*, 897, 898, 907, 1035, 1113, 1123, 1125\*, 1147\*, 1151,
1155, 1165.
\:{character set dependencies}, 23\*, 49\*.
\:{check sum}, 53, 542, 588.
\:\\{check\_byte\_range}, \[570], 573, 574.
\:\\{check\_dimensions}, \[726], 727, 733, 754.
\:\\{check\_full\_save\_stack}, \[273], 274, 276, 280.
\:\\{check\_interrupt}, \[96], 324, 343, 1031.
\:\\{check\_mem}, 165, \[167], 1031, 1339.
\:\\{check\_outer\_validity}, \[336\*], 351, 353, 354, 357, 362, 375.
\:\\{check\_shrinkage}, \[825], 827, 869.
\:{Chinese characters}, 134\*, 585.
\:\\{choice\_node}, 688, \[689], 690, 698, 730.
\:\\{choose\_mlist}, \[731].
\:\\{chr}, 19, 20, 23\*, 24, 31\*, 485\*, 538\*, 1222.
\:\\{chr\_cmd}, \[298], 781.
\:\\{chr\_code}, 227, 231, 239, 249, \[298], 377, 385, 411, 412, 413, 417, 469,
488, 492, 781, 984, 1053, 1059, 1071, 1072, 1089, 1108, 1115, 1143, 1157, 1170,
1179, 1189, 1209, 1220, 1223, 1231, 1251, 1255, 1261, 1263, 1273, 1278, 1287,
1289, 1292, 1346.
\:\\{clean\_box}, \[720], 734, 735, 737, 738, 742, 744, 749, 750, 757, 758, 759.
\:\\{clear\_for\_error\_prompt}, 78, 83, \[330], 346.
\:\\{clear\_terminal}, \[34\*], 330, 530\*.
\:\.{CLOBBERED}, 293.
\:\\{clobbered}, \[167], 168, 169.
\:\\{close}, 28.
\:\\{close\_files\_and\_terminate}, 78, 81, 1332, \[1333\*].
\:\9{close\_in\_}{\.{\\closein} primitive}, \[1272].
\:\\{close\_noad}, \[682], 690, 696, 698, 728, 761, 762, 1156, 1157.
\:\\{close\_node}, \[1341], 1344, 1346, 1348, 1356, 1357, 1358, 1373, 1374,
1375.
\:\9{close\_out\_}{\.{\\closeout} primitive}, \[1344].
\:\\{closed}, \[480], 481, 483, 485\*, 486, 501, 1275.
\:\\{clr}, \[737], \[743], 745, 746, \[756], 757, 758, 759.
\:\\{club\_penalty}, \[236], 890.
\:\9{club\_penalty\_}{\.{\\clubpenalty} primitive}, \[238].
\:\\{club\_penalty\_code}, \[236], 237, 238.
\:\.{cm}, 458.
\:\\{cmd}, \[298], 1222, 1289.
\:\\{combine\_two\_deltas}, \[860].
\:\\{comment}, \[207], 232\*, 347.
\:\\{common\_ending}, \[15], 498, 500, 509, 649, 660, 666, 667, 668, 674, 677,
678, 1257, 1260, 1293, 1294, 1297.
\:\.{Completed box...}, 638.
\:\\{compress\_trie}, \[948], 960.
\:\\{cond\_math\_glue}, \[149], 189, 732, 1171.
\:\\{cond\_ptr}, \[489], 490, 495, 496, 497, 498, 500, 509, 1335\*.
\:\\{conditional}, 366\*, 367, \[498].
\:\\{confusion}, \[95], 202, 206, 281, 497, 630, 669, 728, 736, 754, 761, 766,
791, 798, 800, 841\*, 842\*, 866, 871\*, 877, 968, 973, 1000, 1068\*, 1185,
1200, 1211, 1335\*, 1348, 1357, 1358, 1373.
\:\\{continental\_point\_token}, \[438], 448\*.
\:\\{continue}, \[15], 82, 83, 84\*, 88, 89, 389, 392, 393, 394, 397, 706, 708,
774, 784, 829, 832, 851, 906, 907, 909, 994, 1001.
\:\\{contrib\_head}, \[162], 215, 218, 988, 994, 995, 998, 999, 1001, 1017,
1023, 1026.
\:\\{contrib\_tail}, \[995], 1017, 1023, 1026.
\:\\{contribute}, \[994], 997, 1000, 1002, 1008, 1363.
\:\\{conv\_toks}, 366\*, 367, \[470].
\:{conventions for representing stacks}, 300.
\:\\{convert}, \[210], 366\*, 367, 468, 469, 470.
\:\\{convert\_to\_break\_width}, \[843].
\:\9{copy\_}{\.{\\copy} primitive}, \[1071].
\:\\{copy\_code}, \[1071], 1072, 1079, 1107, 1108, 1110.
\:\\{copy\_node\_list}, 161, 203, \[204], 206, 1079, 1110.
\:\\{copy\_to\_cur\_active}, \[829], 861.
\:\\{count}, \[236], 427, 638, 640, 986, 1008, 1009, 1010.
\:\9{count\_}{\.{\\count} primitive}, \[411].
\:\\{count\_base}, \[236], 239, 242, 1224, 1237.
\:\9{count\_def\_}{\.{\\countdef} primitive}, \[1222].
\:\\{count\_def\_code}, \[1222], 1223, 1224.
\:\9{cr\_}{\.{\\cr} primitive}, \[780].
\:\\{cr\_code}, \[780], 781, 789, 791, 792.
\:\9{cr\_cr\_}{\.{\\crcr} primitive}, \[780].
\:\\{cr\_cr\_code}, \[780], 785, 789.
\:\\{cramped}, \[688], 702.
\:\\{cramped\_style}, \[702], 734, 737, 738.
\:\\{cs\_count}, \[256], 258, 260, 1318, 1319, 1334.
\:\\{cs\_error}, 1134, \[1135].
\:\\{cs\_name}, \[210], 265\*, 266\*, 366\*, 367.
\:\9{cs\_name\_}{\.{\\csname} primitive}, \[265\*].
\:\\{cs\_token\_flag}, \[289], 290, 293, 334, 336\*, 337, 339, 357, 358, 365,
369, 372, 375, 379, 380, 381, 442, 466, 506, 780, 1065, 1132, 1215, 1289, 1314,
1371.
\:\\{cur\_active\_width}, \[823], 824, 829, 832, 837, 843, 844, 851, 852, 853,
860.
\:\\{cur\_align}, \[770], 771, 772, 777, 778, 779, 783, 786, 788, 789, 791,
792, 795, 796, 798.
\:\\{cur\_area}, \[512], 517\*, 529, 530\*, 535, 537, 1257, 1260, 1351, 1374.
\:\\{cur\_boundary}, 270, \[271], 272, 274, 282.
\:\\{cur\_box}, \[1074], 1075, 1076, 1077, 1078, 1079, 1080, 1081, 1082, 1084,
1086, 1087.
\:\\{cur\_break}, \[821], 845, 879, 880, 881, 883.
\:\\{cur\_c}, 722, 723, \[724], 738, 749, 752, 753, 755.
\:\\{cur\_chr}, 88, 296, \[297], 299, 332, 337, 341\*, 343, 348, 349, 351, 352,
353, 354, 355, 356, 357, 358, 359, 360, 364, 365, 378, 380, 381, 386, 387, 389,
403, 407\*, 413, 424, 428, 442, 470, 472, 474, 476, 479, 483, 494\*, 495, 498,
500, 506, 507, 508, 509, 510, 526, 577, 782, 785, 789, 935, 937, 962, 1030,
1033, 1036, 1049, 1058, 1060, 1061, 1066, 1073, 1079, 1083, 1090\*, 1093, 1105,
1106, 1110, 1117, 1124\*, 1128, 1140, 1142, 1151, 1152, 1154, 1155, 1158, 1159,
1160, 1171, 1181, 1191, 1211, 1212, 1213, 1217, 1218, 1221, 1224, 1226, 1227,
1228, 1232, 1233, 1234, 1237, 1243, 1245, 1246, 1247, 1252, 1253, 1265, 1275,
1279, 1288, 1293, 1335\*, 1348, 1350, 1375.
\:\\{cur\_cmd}, 88, 211, 296, \[297], 299, 332, 337, 341\*, 342, 343, 344, 348,
349, 351, 353, 354, 357, 358, 360, 364, 365, 366\*, 367, 368, 372, 380, 381,
386, 387, 403, 404, 406, 407\*, 413, 415, 428, 440\*, 442, 443, 444, 448\*,
452, 455, 461, 463, 474, 476, 477, 478, 479, 483, 494\*, 506, 507, 526, 577,
777, 782, 783, 784, 785, 788, 789, 935, 961, 1029, 1030, 1036, 1049, 1066,
1078, 1079, 1084, 1095, 1099, 1124\*, 1128, 1138, 1151, 1152, 1160, 1165, 1176,
1177, 1197, 1206, 1211, 1212, 1213, 1221, 1226, 1227, 1228, 1236, 1237, 1252,
1270, 1375.
\:\\{cur\_cs}, \[297], 332, 333, 336\*, 337, 338, 341\*, 351, 353, 354, 356,
357, 358, 365, 372, 374, 379, 380, 381, 389, 391, 407\*, 472, 473, 507, 774,
1152, 1215, 1218, 1221, 1224, 1225, 1226, 1257, 1294, 1352, 1371.
\:\\{cur\_ext}, \[512], 517\*, 529, 530\*, 535, 537, 1275, 1351, 1374.
\:\\{cur\_f}, 722, \[724], 738, 741, 749, 752, 753, 755.
\:\\{cur\_fam}, \[236], 1151, 1155, 1165.
\:\\{cur\_fam\_code}, \[236], 237, 238, 1139, 1145.
\:\\{cur\_file}, \[304\*], 329\*, 362, 537, 538\*.
\:\\{cur\_font}, \[230], 232\*, 558, 559, 577, 1033, 1042, 1044, 1117, 1122\*,
1123, 1124\*, 1146.
\:\\{cur\_font\_loc}, \[230], 232\*, 233, 234, 1217.
\:\\{cur\_group}, 270, \[271], 272, 274, 281, 282, 800, 1062, 1063\*, 1064,
1065, 1067, 1068\*, 1069, 1131, 1142, 1191, 1192, 1193, 1194, 1200, 1335\*.
\:\\{cur\_h}, \[616], 617, 618, 619, 620\*, 622, 623, 626, 627, 628, 629, 632,
637.
\:\\{cur\_head}, \[770], 771, 772, 786, 799.
\:\\{cur\_height}, \[970], 972, 973, 974, 975, 976.
\:\\{cur\_i}, 722, 723, \[724], 738, 741, 749, 752, 753, 755.
\:\\{cur\_if}, 336\*, \[489], 490, 495, 496, 1335\*.
\:\\{cur\_indent}, \[877], 889.
\:\\{cur\_input}, 36, 87, \[301], 302, 311, 321, 322, 534.
\:\\{cur\_length}, \[41], 180, 182, 617, 692, 1368.
\:\\{cur\_level}, 270, \[271], 272, 274, 277, 278, 281, 1304, 1335\*.
\:\\{cur\_line}, \[877], 889, 890.
\:\\{cur\_list}, \[213], 216, 217, 218, 422, 1244.
\:\\{cur\_loop}, \[770], 771, 772, 777, 783, 792, 793, 794.
\:\\{cur\_mark}, 296, \[382], 386.
\:\\{cur\_mlist}, \[719], 720, 726, 754, 1194, 1196, 1199.
\:\\{cur\_mu}, 703, \[719], 730, 732, 766.
\:\\{cur\_name}, \[512], 517\*, 529, 530\*, 535, 537, 1257, 1258, 1260, 1351,
1374.
\:\\{cur\_order}, \[447], 448\*, 454, 462.
\:\\{cur\_p}, 823, \[828], 829, 830, 833, 837, 839, 840, 845, 851, 853, 855,
856, 857, 858, 859, 860, 862, 863, 865, 866, 867\*, 868, 869, 870, 872, 877,
878, 879, 880, 881, 883, 894, 903.
\:\\{cur\_s}, \[616], 617, 619, 629.
\:\\{cur\_size}, 700, 701, 703, \[719], 722, 723, 732, 736, 737, 744, 746, 747,
748, 749, 757, 758, 759, 762.
\:\\{cur\_span}, \[770], 771, 772, 787, 796, 798.
\:\\{cur\_style}, 703, \[719], 720, 726, 730, 731, 734, 735, 737, 738, 742,
744, 745, 746, 748, 749, 750, 754, 756, 757, 758, 759, 760, 763, 766, 1194,
1196, 1199.
\:\\{cur\_tail}, \[770], 771, 772, 786, 796, 799.
\:\\{cur\_tok}, 88, 281, \[297], 325, 326, 327, 336\*, 364, 365, 366\*, 368,
369, 372, 375, 379, 380, 381, 392, 393, 394, 395, 397, 399, 403, 405, 407\*,
440\*, 441, 442, 444, 445, 448\*, 452, 474, 476, 477, 479, 483, 494\*, 503,
506, 783, 784, 1036, 1047, 1095, 1127, 1128, 1132, 1215, 1221, 1268, 1269,
1271, 1371, 1372.
\:\\{cur\_v}, \[616], 618, 619, 623, 624, 628, 629, 631, 632, 633, 635, 636,
637, 640.
\:\\{cur\_val}, 264, 265\*, 334, 366\*, \[410], 413, 414, 415, 418, 419, 420,
421, 423, 424, 425, 426, 427, 429, 430, 431, 432, 433, 434, 435\*, 436, 437,
438, 439, 440\*, 442, 444, 445, 447, 448\*, 450, 451, 453, 455, 457, 458, 460,
461, 462, 463, 465, 466, 472, 482, 491, 501, 503, 504, 505, 509, 553, 577, 578,
579, 580, 645, 780, 782, 935, 1030, 1036, 1060, 1061, 1073, 1079, 1082, 1099,
1103, 1110, 1122\*, 1123, 1124\*, 1151, 1154, 1160, 1161, 1165, 1182, 1188,
1224, 1225, 1226, 1227, 1228, 1229, 1232, 1234, 1236, 1237, 1238, 1239, 1240,
1241, 1243, 1244, 1245, 1246, 1247, 1248, 1253, 1258, 1259, 1275, 1296, 1344,
1350.
\:\\{cur\_val\_level}, 366\*, \[410], 413, 418, 419, 420, 421, 423, 424, 427,
429, 430, 439, 449, 451, 455, 461, 465, 466.
\:\\{cur\_width}, \[877], 889.
\:{current page}, 980.
\:\\{current\_character\_being\_worked\_on}, \[570].
\:\\{cv\_backup}, \[366\*].
\:\\{cvl\_backup}, \[366\*].
\:\|{d}, \[107], \[176\*], \[177], \[440\*], \[523\*], \[560], \[649], \[668], %
\[679], \[706], \[830], \[906], \[944], \[970], \[1068\*], \[1086], \[1138], %
\[1198].
\:\\{d\_fixed}, \[608], 609.
\:\\{danger}, \[1194], 1195, 1199.
\:\\{data}, \[210], 232\*, 1217, 1232, 1234.
\:{data structure assumptions}, \[161], 164, 204, 816, 968, 981.
\:\\{date}, 241\*.
\:\\{day}, \[236], 241\*, 536, 617, 1328.
\:\9{day\_}{\.{\\day} primitive}, \[238].
\:\\{day\_code}, \[236], 237, 238.
\:\.{dd}, 458.
\:\\{deactivate}, \[829], 851, 854.
\:\\{dead\_cycles}, 419, \[592], 593, 638, 1012, 1024, 1025, 1054, 1242, 1246.
\:\9{dead\_cycles\_}{\.{\\deadcycles} primitive}, \[416].
\:\&{debug}, \[7\*], \[9\*], \[37\*], \[78], \[84\*], \[93], \[114], \[165], %
\[166], \[167], \[172], \[1031], \[1338].
\:\.{debug \#}, 1338.
\:\\{debug\_help}, 78, 84\*, 93, \[1338].
\:{debugging}, 7\*, 84\*, 96, 114, 165, 182, 1031, 1338.
\:\\{decent\_fit}, \[817], 834, 852, 853, 864.
\:\\{decr}, \[16], 31\*, 42, 44, 64, 71\*, 86, 88, 89, 90, 92, 102, 120, 121,
123, 175, 177, 200, 201, 205, 217, 245, 260, 281, 282, 311, 322, 324, 325, 329%
\*, 331, 341\*, 347, 356, 357, 360, 362, 363\*, 366\*, 394, 399, 407\*, 422,
429, 440\*, 442, 448\*, 477, 483, 494\*, 509, 534, 538\*, 568, 576, 601, 619,
629, 638, 642\*, 643, 803, 808, 840, 841\*, 858, 883, 915, 930, 940, 944, 947,
965, 1060, 1063\*, 1068\*, 1100, 1120, 1127, 1174, 1186, 1194, 1244, 1293,
1311, 1335\*, 1337.
\:\\{def}, \[209\*], 1208, 1209, 1210, 1213, 1218.
\:\9{def\_}{\.{\\def} primitive}, \[1208].
\:\\{def\_code}, \[209\*], 413, 1210, 1230, 1231, 1232.
\:\\{def\_family}, \[209\*], 413, 577, 1210, 1230, 1231, 1234.
\:\\{def\_font}, \[209\*], 265\*, 266\*, 413, 577, 1210, 1256.
\:\\{def\_ref}, \[305], 306, 473, 482, 1101, 1218, 1226, 1279, 1288, 1352,
1354, 1370.
\:\\{default\_code}, \[683], 697, 743, 1182.
\:\\{default\_hyphen\_char}, \[236], 576.
\:\9{default\_hyphen\_char\_}{\.{\\defaulthyphenchar} primitive}, \[238].
\:\\{default\_hyphen\_char\_code}, \[236], 237, 238.
\:\\{default\_rule}, \[463].
\:\\{default\_rule\_thickness}, 683, \[701], 734, 735, 737, 743, 745, 759.
\:\\{default\_skew\_char}, \[236], 576.
\:\9{default\_skew\_char\_}{\.{\\defaultskewchar} primitive}, \[238].
\:\\{default\_skew\_char\_code}, \[236], 237, 238.
\:{defecation}, 597\*.
\:\\{define}, \[1214], 1217, 1218, 1221, 1224, 1225, 1226, 1227, 1228, 1232,
1234, 1236, 1248, 1257.
\:\\{defining}, \[305], 306, 339, 473, 482.
\:\\{del\_code}, \[236], 240, 1160.
\:\9{del\_code\_}{\.{\\delcode} primitive}, \[1230].
\:\\{del\_code\_base}, \[236], 240, 242, 1230, 1232, 1233.
\:\\{delete\_glue\_ref}, \[201], 202, 275, 451, 465, 578, 732, 802, 816, 826,
881, 976, 996, 1004, 1017, 1022, 1100, 1229, 1239.
\:\\{delete\_last}, 1104, \[1105].
\:\\{delete\_q}, \[726], 760, 763.
\:\\{delete\_token\_ref}, \[200], 202, 275, 324, 977, 979, 1012, 1016, 1358.
\:\\{deletions\_allowed}, \[76], 77, 84\*, 85, 98, 336\*, 346.
\:\\{delim\_num}, \[207], 265\*, 266\*, 1046\*, 1151, 1154, 1160.
\:\\{delimited\_code}, \[1178], 1179, 1182, 1183.
\:\\{delimiter}, \[687], 762, 1191.
\:\9{delimiter\_}{\.{\\delimiter} primitive}, \[265\*].
\:\\{delimiter\_factor}, \[236], 762.
\:\9{delimiter\_factor\_}{\.{\\delimiterfactor} primitive}, \[238].
\:\\{delimiter\_factor\_code}, \[236], 237, 238.
\:\\{delimiter\_shortfall}, \[247], 762.
\:\9{delimiter\_shortfall\_}{\.{\\delimitershortfall} primitive}, \[248].
\:\\{delimiter\_shortfall\_code}, \[247], 248.
\:\\{delim1}, \[700], 748.
\:\\{delim2}, \[700], 748.
\:\\{delta}, \[103], \[726], 728, 733, \[735], \[736], \[737], \[738], 742, %
\[743], 745, 746, 747, 748, \[749], 750, 754, 755, \[756], 759, \[762], \[994],
1008, 1010, \[1123], 1125\*.
\:\\{delta\_node}, \[822], 830, 832, 843, 844, 860, 861, 865, 874, 875.
\:\\{delta\_node\_size}, \[822], 843, 844, 860, 861, 865.
\:\\{delta1}, \[743], 746, \[762].
\:\\{delta2}, \[743], 746, \[762].
\:\\{den}, 585, \[587], 590.
\:\\{denom}, \[450], 458.
\:\\{denom\_style}, \[702], 744.
\:\\{denominator}, \[683], 690, 697, 698, 744, 1181, 1185.
\:\\{denom1}, \[700], 744.
\:\\{denom2}, \[700], 744.
\:\\{deplorable}, \[974], 1005.
\:\.{depth}, 463.
\:\\{depth}, \[135], 136, 138, 139, 140, 184, 187, 188, 463, 554, 622, 624,
626, 631, 632, 635, 641, 649, 653, 656, 668, 670, 679, 688, 704, 706, 709, 713,
727, 730, 731, 735, 736, 737, 745, 746, 747, 749, 750, 751, 756, 758, 759, 768,
769, 801, 806, 810, 973, 1002, 1009, 1010, 1021, 1087, 1100.
\:\\{depth\_base}, \[550], 552, 554, 566, 571, 1322, 1323.
\:\\{depth\_index}, \[543], 554.
\:\\{depth\_offset}, \[135], 416, 769, 1247.
\:\\{depth\_threshold}, \[181], 182, 198, 233, 236, 692, 1339.
\:\\{dig}, \[54], 64, 65, 67, 102, 452.
\:\\{digit\_sensed}, \[960], 961, 962.
\:\\{dimen}, \[247], 427, 1008, 1010.
\:\9{dimen\_}{\.{\\dimen} primitive}, \[411].
\:\\{dimen\_base}, 220, \[236], 247, 248, 249, 250, 251, 252, 1070, 1145.
\:\9{dimen\_def\_}{\.{\\dimendef} primitive}, \[1222].
\:\\{dimen\_def\_code}, \[1222], 1223, 1224.
\:\\{dimen\_par}, \[247].
\:\\{dimen\_pars}, \[247].
\:\\{dimen\_val}, \[410], 411, 412, 413, 415, 416, 417, 418, 420, 421, 424,
425, 427, 428, 429, 449, 455, 465, 1237.
\:\.{Dimension too large}, 460.
\:{dirty \PASCAL}, \[3], 114, 172, 182, 186, 285, 1331.
\:\\{disc\_break}, \[877], 880, 881, 882, 890.
\:\\{disc\_group}, \[269], 1117, 1118, 1119.
\:\\{disc\_node}, \[145], 148, 175, 183\*, 202, 206, 730, 761, 817, 819, 829,
856, 858, 866, 881, 914, 1081, 1105.
\:\\{disc\_width}, \[839], 840, 870, 871\*.
\:\\{discretionary}, \[208\*], 1090\*, 1114, 1115, 1116.
\:\.{Discretionary list is too long}, 1120.
\:\9{discretionary\_}{\.{\\discretionary} primitive}, \[1114].
\:\.{Display math...with \$\$}, 1197.
\:\\{display\_indent}, \[247], 800, 1138, 1145, 1199.
\:\9{display\_indent\_}{\.{\\displayindent} primitive}, \[248].
\:\\{display\_indent\_code}, \[247], 248, 1145.
\:\9{display\_limits\_}{\.{\\displaylimits} primitive}, \[1156].
\:\\{display\_mlist}, \[689], 695, 698, 731, 1174.
\:\\{display\_style}, \[688], 694, 731, 1169, 1199.
\:\9{display\_style\_}{\.{\\displaystyle} primitive}, \[1169].
\:\\{display\_widow\_penalty}, \[236], 1145.
\:\9{display\_widow\_penalty\_}{\.{\\displaywidowpenalty} primitive}, \[238].
\:\\{display\_widow\_penalty\_code}, \[236], 237, 238.
\:\\{display\_width}, \[247], 1138, 1145, 1199.
\:\9{display\_width\_}{\.{\\displaywidth} primitive}, \[248].
\:\\{display\_width\_code}, \[247], 248, 1145.
\:\&{div}, \[100], \[627], \[636].
\:\\{divide}, \[209\*], 265\*, 266\*, 1210, 1235, 1236.
\:\9{divide\_}{\.{\\divide} primitive}, \[265\*].
\:\\{do\_all\_six}, \[823], 829, 832, 837, 843, 844, 860, 861, 864, 970, 987.
\:\\{do\_assignments}, 800, 1123, 1206, \[1270].
\:\\{do\_endv}, 1130, \[1131].
\:\\{do\_extension}, 1347, \[1348], 1375.
\:\\{do\_nothing}, \[16], 33\*, 57, 58, 84\*, 175, 202, 275, 344, 357, 569,
609, 611, 612, 622, 631, 651, 669, 692, 728, 733, 761, 837, 866, 899\*, 1045,
1236, 1359, 1360, 1362.
\:\\{do\_register\_command}, 1235, \[1236].
\:\\{doing\_leaders}, \[592], 593, 628, 637, 1374.
\:\\{done}, \[15], 31\*, 47, 53, 174\*, 202, 281, 282, 311, 380, 389, 397, 440%
\*, 445, 448\*, 453, 458, 473, 474, 476, 482, 483, 494\*, 526, 530\*, 531, 537,
560, 567, 576, 615, 638, 640, 641, 698, 726, 738, 740, 760, 761, 774, 777, 815,
829, 837, 863, 873, 877, 881, 895, 906, 907, 908, 931, 934, 939, 960, 961, 970,
974, 977, 979, 994, 997, 998, 1005, 1079, 1081, 1119, 1121, 1138, 1146, 1211,
1227, 1252, 1358.
\:\\{done\_with\_noad}, \[726], 727, 728, 733, 754.
\:\\{done\_with\_node}, \[726], 727, 730, 731, 754.
\:\\{done1}, \[15], 167, 168, 389, 399, 448\*, 452, 473, 474, 738, 741, 774,
783, 815, 829, 852, 877, 879, 894, 896\*, 899\*, 960, 965, 994, 997, 1000,
1302, 1315.
\:\\{done2}, \[15], 167, 169, 448\*, 458, 459, 473, 478, 774, 784, 815, 896\*,
1302, 1316.
\:\\{done3}, \[15], 815, 897, 898.
\:\\{done4}, \[15], 815, 899\*.
\:\\{done5}, \[15].
\:\\{done6}, \[15].
\:\\{dont\_expand}, \[210], 258, 357, 369.
\:\.{Double subscript}, 1177.
\:\.{Double superscript}, 1177.
\:\\{double\_hyphen\_demerits}, \[236], 859.
\:\9{double\_hyphen\_demerits\_}{\.{\\doublehyphendemerits} primitive}, \[238].
\:\\{double\_hyphen\_demerits\_code}, \[236], 237, 238.
\:\.{Doubly free location...}, 169.
\:\\{down\_ptr}, \[605], 606, 607, 615.
\:\\{downdate\_width}, \[860].
\:\\{down1}, 585, \[586], 607, 609, 610, 613, 614, 616.
\:\\{down2}, \[585], 594\*, 610.
\:\\{down3}, \[585], 610.
\:\\{down4}, \[585], 610.
\:\9{dp\_}{\.{\\dp} primitive}, \[416].
\:{dry rot}, 95.
\:\9{dump\_}{\.{\\dump...only by INITEX}}, 1335\*.
\:\9{dump\_}{\.{\\dump} primitive}, \[1052].
\:\\{dump\_four\_ASCII}, \[1309].
\:\\{dump\_hh}, \[1305], 1318, 1324.
\:\\{dump\_int}, \[1305], 1307, 1309, 1311, 1313, 1315, 1316, 1318, 1320, 1322,
1324, 1326.
\:\\{dump\_qqqq}, \[1305], 1309, 1322.
\:\\{dump\_wd}, \[1305], 1311, 1315, 1316, 1320.
\:\.{Duplicate pattern}, 963.
\:\\{dvi\_buf}, 594\*, \[595\*], 597\*, 598, 607, 613, 614.
\:\\{dvi\_buf\_size}, \[11\*], 14, 594\*, 595\*, 596, 598, 599, 607, 613, 614,
642\*.
\:\\{dvi\_f}, \[616], 617, 620\*, 621.
\:\\{dvi\_file}, \[532], 592, 595\*, 597\*, 642\*.
\:\9{DVI\_files}{\.{DVI} files}, 583.
\:\\{dvi\_font\_def}, \[602], 621, 643.
\:\\{dvi\_four}, \[600], 602, 610, 617, 624, 633, 640, 642\*, 1368.
\:\\{dvi\_gone}, 594\*, \[595\*], 596, 598, 612.
\:\\{dvi\_h}, \[616], 617, 619, 620\*, 623, 624, 628, 629, 632, 637.
\:\\{dvi\_index}, \[594\*], 595\*, 597\*.
\:\\{dvi\_limit}, 594\*, \[595\*], 596, 598, 599.
\:\\{dvi\_offset}, 594\*, \[595\*], 596, 598, 601, 605, 607, 613, 614, 619,
629, 640, 642\*.
\:\\{dvi\_out}, \[598], 600, 601, 602, 603, 609, 610, 617, 619, 620\*, 621,
624, 629, 633, 640, 642\*, 1368.
\:\\{dvi\_pop}, \[601], 619, 629.
\:\\{dvi\_ptr}, 594\*, \[595\*], 596, 598, 599, 601, 607, 619, 629, 640, 642\*.
\:\\{dvi\_swap}, \[598].
\:\\{dvi\_v}, \[616], 617, 619, 623, 628, 629, 632, 637.
\:\\{dyn\_used}, \[117], 120, 121, 122, 123, 164, 639, 1311, 1312.
\:\|{e}, \[277], \[279], \[518\*], \[519\*], \[530\*], \[1198], \[1211].
\:\\{easy\_line}, 819, 835, \[847], 848, 850.
\:\\{ec}, 540, 541, 543, \[560], 565, 566, 570, 576.
\:\9{edef\_}{\.{\\edef} primitive}, \[1208].
\:\\{edge}, \[619], 623, 626, \[629], 635.
\:\\{eight\_bits}, \[25], 64, 112\*, 297, 549, 560, 581, 582\*, 594\*, 607,
649, 706, 709, 712, 977, 992, 993, 1032, 1079, 1247, 1288.
\:\\{eject\_penalty}, \[157], 829, 831, 851, 859, 873, 970, 972, 974, 1005,
1010, 1011.
\:\&{else}, 10.
\:\9{else\_}{\.{\\else} primitive}, \[491].
\:\\{else\_code}, \[489], 491, 498.
\:\.{em}, 455.
\:\.{Emergency stop}, 93.
\:\\{empty}, \[16], 421, 681, 685, 687, 692, 722, 723, 738, 749, 751, 752, 754,
755, 756, 980, 986, 987, 991, 1001, 1008, 1176, 1177, 1186.
\:{empty line at end of file}, 486, 538\*.
\:\\{empty\_field}, \[684], 685, 686, 742, 1163, 1165, 1181.
\:\\{empty\_flag}, \[124], 126, 130, 150, 164, 1312.
\:\&{end}, 7\*, 8\*, 10.
\:\.{End of file on the terminal}, 37\*, 71\*, 363\*.
\:\9{end\_}{\.{(\\end occurred...)}}, 1335\*.
\:\9{end\_}{\.{\\end} primitive}, \[1052].
\:\\{end\_cs\_name}, \[208\*], 265\*, 266\*, 372, 1134.
\:\9{end\_cs\_name\_}{\.{\\endcsname} primitive}, \[265\*].
\:\\{end\_diagnostic}, \[245], 284, 299, 323, 400, 401, 502, 509, 581, 638,
641, 663\*, 675\*, 863, 987, 992, 1006, 1011, 1121, 1298.
\:\\{end\_file\_reading}, \[329\*], 330, 360, 362, 483, 537.
\:\\{end\_graf}, 1026, 1085, 1094, \[1096], 1100, 1131, 1133, 1168.
\:\\{end\_group}, \[208\*], 265\*, 266\*, 1063\*.
\:\9{end\_group\_}{\.{\\endgroup} primitive}, \[265\*].
\:\9{end\_input\_}{\.{\\endinput} primitive}, \[376].
\:\\{end\_line\_char}, 87, \[236], 240, 303, 318, 332, 360, 362, 483, 534, 538%
\*, 1337.
\:\9{end\_line\_char\_}{\.{\\endlinechar} primitive}, \[238].
\:\\{end\_line\_char\_code}, \[236], 237, 238.
\:\\{end\_match}, \[207], 289, 291, 294, 391, 392, 394.
\:\\{end\_match\_token}, \[289], 389, 391, 392, 393, 394, 474, 476, 482.
\:\\{end\_name}, 512, \[517\*], 526, 531.
\:\\{end\_of\_TEX}, \[6], 81, 1332.
\:\\{end\_span}, \[162], 768, 779, 793, 797, 801, 803.
\:\\{end\_template}, \[210], 366\*, 375, 380, 780, 1295.
\:\\{end\_template\_token}, \[780], 784, 790.
\:\\{end\_token\_list}, \[324], 325, 357, 390, 1026, 1371.
\:\\{end\_write}, \[222], 1369, 1371.
\:\9{end\_write\_}{\.{\\endwrite}}, 1369.
\:\\{end\_write\_token}, \[1371], 1372.
\:\&{endcases}, \[10].
\:\\{endv}, \[207], 298, 375, 380, 768, 780, 791, 1046\*, 1130.
\:\\{ensure\_dvi\_open}, \[532], 617.
\:\\{ensure\_vbox}, \[993], 1009, 1018.
\:\\{eof}, 26, 31\*, 52, 485\*, 538\*, 564, 575, 1327.
\:\\{eoln}, 31\*, 33\*, 37\*, 52.
\:\\{eop}, 583, 585, \[586], 588, 640.
\:\\{eq\_define}, \[277], 278, 279, 782, 1070, 1077, 1214.
\:\\{eq\_destroy}, \[275], 277, 279, 283.
\:\\{eq\_level}, \[221], 222, 228, 232\*, 236, 253, 264, 277, 279, 283, 780,
977, 1315, 1369.
\:\\{eq\_level\_field}, \[221].
\:\\{eq\_no}, \[208\*], 1140, 1141, 1143, 1144.
\:\9{eq\_no\_}{\.{\\eqno} primitive}, \[1141].
\:\\{eq\_save}, \[276], 277, 278.
\:\\{eq\_type}, 210, \[221], 222, 223, 228, 232\*, 253, 258, 264, 265\*, 267,
277, 279, 351, 353, 354, 357, 358, 372, 389, 391, 780, 1152, 1315, 1369.
\:\\{eq\_type\_field}, \[221], 275.
\:\\{eq\_word\_define}, \[278], 279, 1070, 1139, 1145, 1214.
\:\\{eqtb}, 115, 163, 220, 221, 222, 223, 224, 228, 230, 232\*, 236, 240, 242,
247, 250, 251, 252, \[253], 255, 262, 264, 265\*, 266\*, 267, 268, 270, 272,
274, 275, 276, 277, 278, 279, 281, 282, 283, 284, 285, 286, 289, 291, 297, 298,
305, 307, 332, 333, 354, 372, 389, 413, 414, 473, 491, 548, 553, 780, 814,
1188, 1208, 1222, 1238, 1240, 1253, 1257, 1315, 1316, 1317, 1339, 1345.
\:\\{eqtb\_size}, 220, \[247], 250, 252, 253, 254, 1307, 1308, 1316, 1317.
\:\\{equiv}, \[221], 222, 223, 224, 228, 229, 230, 232\*, 233, 234, 235, 253,
255, 264, 265\*, 267, 275, 277, 279, 351, 353, 354, 357, 358, 413, 414, 415,
508, 577, 780, 1152, 1227, 1239, 1240, 1257, 1289, 1315, 1369.
\:\\{equiv\_field}, \[221], 275, 285.
\:\\{err\_help}, 79, \[230], 1283, 1284.
\:\9{err\_help\_}{\.{\\errhelp} primitive}, \[230].
\:\\{err\_help\_loc}, \[230].
\:\9{err\_message\_}{\.{\\errmessage} primitive}, \[1277].
\:\\{error}, 72, 75, 76, 78, 79, \[82], 88, 91, 93, 98, 327, 338, 346, 370,
398, 408, 418, 428, 445, 454, 456, 459, 460, 475, 476, 486, 500, 510, 523\*,
561, 567, 579, 641, 723, 776, 784, 792, 826, 936, 937, 961, 962, 963, 976, 978,
992, 1004, 1009, 1024, 1027, 1050, 1064, 1066, 1068\*, 1069, 1080, 1082, 1095,
1099, 1106, 1110, 1120, 1121, 1128, 1129, 1135, 1159, 1166, 1177, 1183, 1192,
1195, 1213, 1225, 1232, 1236, 1237, 1252, 1259, 1283, 1284, 1293, 1372, 1377\*.
\:\\{error\_count}, \[76], 77, 82, 86, 1096, 1293.
\:\\{error\_line}, \[11\*], 14, 54, 58, 306, 311, 315, 316, 317.
\:\\{error\_message\_issued}, \[76], 82, 95.
\:\\{error\_stop\_mode}, 72, \[73], 74, 82, 93, 98, 1262, 1283, 1293, 1294,
1297, 1327, 1335\*.
\:\9{error\_stop\_mode\_}{\.{\\errorstopmode} primitive}, \[1262].
\:\\{erstat}, \[27\*].
\:\\{escape}, \[207], 232\*, 344, 1337.
\:\\{escape\_char}, \[236], 240, 243.
\:\9{escape\_char\_}{\.{\\escapechar} primitive}, \[238].
\:\\{escape\_char\_code}, \[236], 237, 238.
\:\\{esci}, \[37\*].
\:\.{etc}, 182.
\:\.{ETC}, 292.
\:\\{every\_cr}, \[230], 774, 799.
\:\9{every\_cr\_}{\.{\\everycr} primitive}, \[230].
\:\\{every\_cr\_loc}, \[230], 231.
\:\\{every\_cr\_text}, \[307], 314, 774, 799.
\:\\{every\_display}, \[230], 1145.
\:\9{every\_display\_}{\.{\\everydisplay} primitive}, \[230].
\:\\{every\_display\_loc}, \[230], 231.
\:\\{every\_display\_text}, \[307], 314, 1145.
\:\\{every\_hbox}, \[230], 1083.
\:\9{every\_hbox\_}{\.{\\everyhbox} primitive}, \[230].
\:\\{every\_hbox\_loc}, \[230], 231.
\:\\{every\_hbox\_text}, \[307], 314, 1083.
\:\\{every\_job}, \[230], 1030.
\:\9{every\_job\_}{\.{\\everyjob} primitive}, \[230].
\:\\{every\_job\_loc}, \[230], 231.
\:\\{every\_job\_text}, \[307], 314, 1030.
\:\\{every\_math}, \[230], 1139.
\:\9{every\_math\_}{\.{\\everymath} primitive}, \[230].
\:\\{every\_math\_loc}, \[230], 231.
\:\\{every\_math\_text}, \[307], 314, 1139.
\:\\{every\_par}, \[230], 1091.
\:\9{every\_par\_}{\.{\\everypar} primitive}, \[230].
\:\\{every\_par\_loc}, \[230], 231, 307, 1226.
\:\\{every\_par\_text}, \[307], 314, 1091.
\:\\{every\_vbox}, \[230], 1083, 1167.
\:\9{every\_vbox\_}{\.{\\everyvbox} primitive}, \[230].
\:\\{every\_vbox\_loc}, \[230], 231.
\:\\{every\_vbox\_text}, \[307], 314, 1083, 1167.
\:\.{ex}, 455.
\:\\{ex\_hyphen\_penalty}, 145, \[236], 870.
\:\9{ex\_hyphen\_penalty\_}{\.{\\exhyphenpenalty} primitive}, \[238].
\:\\{ex\_hyphen\_penalty\_code}, \[236], 237, 238.
\:\\{ex\_space}, \[208\*], 265\*, 266\*, 1030, 1090\*.
\:\\{exactly}, \[644], 645, 715, 889, 977, 1017, 1062, 1201.
\:\\{exit}, \[15], 16, 37\*, 47, 58, 59, 60, 69, 82, 125, 182, 292, 341\*, 389,
407\*, 461, 497, 498, 524, 582\*, 607, 615, 649, 668, 752, 791, 829, 895, 934,
944, 947, 977, 994, 1012, 1030, 1054, 1079, 1105, 1110, 1113, 1119, 1151, 1159,
1174, 1211, 1236, 1270, 1303, 1335\*, 1338.
\:\\{expand}, \[366\*], 368, 371, 380, 381, 439, 467, 478, 498, 510, 782.
\:\\{expand\_after}, \[210], 265\*, 266\*, 366\*, 367.
\:\9{expand\_after\_}{\.{\\expandafter} primitive}, \[265\*].
\:\\{explicit}, \[155], 1058, 1113.
\:{explicit hyphens}, 1039.
\:\\{ext}, \[174\*], \[176\*].
\:\\{ext\_bot}, \[546], 713, 714.
\:\\{ext\_delimiter}, \[513\*], 515, 516\*, 517\*.
\:\\{ext\_mid}, \[546], 713, 714.
\:\\{ext\_rep}, \[546], 713, 714.
\:\\{ext\_tag}, \[544], 569, 708, 710.
\:\\{ext\_top}, \[546], 713, 714.
\:\\{exten}, \[544].
\:\\{exten\_base}, \[550], 552, 566, 573, 574, 576, 713, 1322, 1323.
\:\\{extensible\_recipe}, 541, \[546].
\:\\{extension}, \[208\*], 1344, 1346, 1347, 1375.
\:{extensions to \TeX}, 2\*, 146, 1340.
\:\\{extern}, 27\*, 34\*, 37\*, 597\*.
\:\.{Extra \\else}, 510.
\:\.{Extra \\endcsname}, 1135.
\:\.{Extra \\fi}, 510.
\:\.{Extra \\or}, 500, 510.
\:\.{Extra \\right.}, 1192.
\:\.{Extra \}, or forgotten x}, 1069.
\:\.{Extra alignment tab...}, 792.
\:\.{Extra x}, 1066.
\:\\{extra\_info}, \[769], 788, 789, 791, 792.
\:\\{extra\_right\_brace}, 1068\*, \[1069].
\:\\{extra\_space}, 547, \[558], 1044.
\:\\{extra\_space\_code}, \[547], 558.
\:{eyes and mouth}, 332.
\:\|{f}, \[27\*], \[28], \[31\*], \[144], \[448\*], \[525\*], \[560], \[577], %
\[578], \[581], \[582\*], \[592], \[597\*], \[602], \[649], \[706], \[709], %
\[711], \[712], \[715], \[716], \[717], \[738], \[830], \[862], \[1032], %
\[1043], \[1068\*], \[1113], \[1123], \[1138], \[1211], \[1257].
\:\\{false}, 27\*, 31\*, 37\*, 45, 46, 47, 51, 76, 80, 88, 89, 98, 106, 107,
166, 167, 168, 169, 264, 284, 299, 323, 327, 331, 336\*, 346, 361, 362, 365,
374, 400, 401, 407\*, 425, 440\*, 441, 445, 447, 448\*, 449, 455, 460, 461,
462, 465, 485\*, 501, 502, 505, 507, 509, 512, 516\*, 524, 526, 528, 538\*,
551, 563, 581, 593, 706, 720, 722, 754, 791, 826, 828, 837, 851, 854, 863, 881,
951, 954, 961, 962, 963, 987, 990, 1006, 1011, 1020, 1026, 1031, 1033, 1051,
1054, 1061, 1101, 1182, 1183, 1191, 1192, 1194, 1199, 1226, 1236, 1258, 1279,
1282, 1283, 1288, 1303, 1336, 1342, 1343, 1352, 1354, 1371, 1374.
\:\\{fam}, \[681], 682, 683, 687, 691, 722, 723, 752, 1151, 1155, 1165.
\:\9{fam\_}{\.{\\fam} primitive}, \[238].
\:\\{fam\_fnt}, \[230], 700, 701, 707, 722, 1195.
\:\\{fam\_in\_range}, \[1151], 1155, 1165.
\:\\{fast\_delete\_glue\_ref}, \[201], 202.
\:\\{fast\_get\_avail}, \[122], 371, 1035.
\:\\{fast\_store\_new\_token}, \[371], 399, 464, 466.
\:\.{Fatal format file error}, 1303.
\:\\{fatal\_error}, 71\*, \[93], 360, 363\*, 484, 530\*, 535, 789.
\:\\{fatal\_error\_stop}, \[76], 77, 82, 93, 535, 1332.
\:\\{fbyte}, \[564], 568, 571, 575.
\:\\{fetch}, \[722], 724, 738, 741, 749, 752, 755.
\:\\{fewest\_demerits}, \[872], 874, 875.
\:\\{fget}, \[564], 565, 568, 571, 575.
\:\9{fi\_}{\.{\\fi} primitive}, \[491].
\:\\{fi\_code}, \[489], 491, 492, 494\*, 498, 500, 509, 510.
\:\\{fi\_or\_else}, \[210], 366\*, 367, 489, 491, 492, 494\*, 510.
\:\.{fil}, 454.
\:\\{fil}, 135, \[150], 164, 177, 454, 650, 659, 665, 1201.
\:\\{fil\_code}, \[1058], 1059, 1060.
\:\\{fil\_glue}, \[162], 164, 1060.
\:\\{fil\_neg\_code}, \[1058], 1060.
\:\\{fil\_neg\_glue}, \[162], 164, 1060.
\:\.{File ended while scanning...}, 338.
\:\.{File ended within \\read}, 486.
\:\\{file\_name\_size}, \[11\*], 26, 519\*, 522, 523\*, 525\*.
\:\\{file\_offset}, \[54], 55, 57, 58, 62, 537, 638, 1280.
\:\\{file\_opened}, \[560], 561, 563.
\:\\{fill}, 135, \[150], 164, 650, 659, 665, 1201.
\:\\{fill\_code}, \[1058], 1059, 1060.
\:\\{fill\_glue}, \[162], 164, 1054, 1060.
\:\\{filll}, 135, \[150], 177, 454, 650, 659, 665, 1201.
\:\\{fin\_align}, 773, 785, \[800], 1131.
\:\\{fin\_col}, 773, \[791], 1131.
\:\\{fin\_mlist}, 1174, \[1184], 1186, 1191, 1194.
\:\\{fin\_row}, 773, \[799], 1131.
\:\\{fin\_rule}, \[619], 622, 626, 629, 631, 635.
\:\\{final\_cleanup}, 1332, \[1335\*].
\:\\{final\_end}, \[6], 331, 1332, 1337.
\:\\{final\_hyphen\_demerits}, \[236], 859.
\:\9{final\_hyphen\_demerits\_}{\.{\\finalhyphendemerits} primitive}, \[238].
\:\\{final\_hyphen\_demerits\_code}, \[236], 237, 238.
\:\\{final\_widow\_penalty}, 814, \[815], 876, \[877], 890.
\:\\{find\_font\_dimen}, 425, \[578], 1042, 1253.
\:{fingers}, 511.
\:\\{finite\_shrink}, 825, \[826].
\:\\{fire\_up}, 1005, \[1012].
\:\\{firm\_up\_the\_line}, 340, 362, \[363\*], 538\*.
\:\\{first}, \[30\*], 31\*, 36, 37\*, 71\*, 83, 87, 88, 328\*, 329\*, 331, 355,
360, 362, 363\*, 374, 483, 531, 538\*.
\:\\{first\_child}, \[960], 963, 964.
\:\\{first\_count}, \[54], 315, 316, 317.
\:\\{first\_fit}, \[953], 957, 966.
\:\\{first\_indent}, \[847], 849, 889.
\:\\{first\_mark}, \[382], 383, 1012, 1016.
\:\9{first\_mark\_}{\.{\\firstmark} primitive}, \[384].
\:\\{first\_mark\_code}, \[382], 384, 385.
\:\\{first\_text\_char}, \[19], 24.
\:\\{first\_width}, \[847], 849, 850, 889.
\:\\{fit\_class}, \[830], 836, 845, 846, 852, 853, 855, 859.
\:\\{fitness}, \[819], 845, 859, 864.
\:\\{fix\_date\_and\_time}, \[241\*], 1337.
\:\\{fix\_word}, \[541], 542, 547, 548, 571.
\:\\{float}, \[109], 114, 186, 625, 634, 809.
\:\\{float\_constant}, \[109], 186, 1123, 1125\*.
\:\\{float\_cost}, \[140], 188, 1008, 1100.
\:\\{floating\_penalty}, 140, \[236], 1068\*, 1100.
\:\9{floating\_penalty\_}{\.{\\floatingpenalty} primitive}, \[238].
\:\\{floating\_penalty\_code}, \[236], 237, 238.
\:\\{flush\_char}, \[42], 180, 195, 692, 695.
\:\\{flush\_list}, \[123], 200, 324, 372, 396, 407\*, 801, 1279, 1297, 1370.
\:\\{flush\_math}, \[718], 776, 1194, 1195.
\:\\{flush\_node\_list}, 199, \[202], 275, 639, 698, 718, 731, 732, 742, 800,
816, 879, 883, 903, 968, 992, 999, 1078, 1105, 1120, 1121, 1375.
\:\\{flush\_string}, \[44], 264, 537, 1279, 1328.
\:\\{fmem\_ptr}, 425, \[549], 552, 566, 569, 570, 576, 578, 579, 580, 1320,
1321, 1334.
\:\\{fmt\_file}, 524, \[1305], 1306, 1308, 1327, 1328, 1329, 1337.
\:\\{fnt\_def1}, 585, \[586], 602.
\:\\{fnt\_def2}, \[585].
\:\\{fnt\_def3}, \[585].
\:\\{fnt\_def4}, \[585].
\:\\{fnt\_num\_0}, 585, \[586], 621.
\:\\{fnt1}, 585, \[586], 621.
\:\\{fnt2}, \[585].
\:\\{fnt3}, \[585].
\:\\{fnt4}, \[585].
\:\\{font}, \[134\*], 143, 144, 174\*, 176\*, 193, 206, 267, 548, 582\*, 620\*,
654\*, 681, 709, 715, 724, 841\*, 842\*, 866, 867\*, 871\*, 896\*, 897, 898,
907, 1035, 1113, 1147\*.
\:{font metric files}, 539.
\:{font parameters}, 700, 701.
\:\.{Font x has only...}, 579.
\:\.{Font x=xx not loadable...}, 561.
\:\.{Font x=xx not loaded...}, 567.
\:\9{font\_}{\.{\\font} primitive}, \[265\*].
\:\\{font\_area}, \[549], 552, 576, 602, 603, 1260, 1322, 1323.
\:\\{font\_base}, \[12\*], 111, 134\*, 174\*, 176\*, 222, 232\*, 548, 551, 582%
\*, 602, 621, 643, 896\*, 1260, 1320, 1321, 1334.
\:\\{font\_bc}, \[549], 552, 576, 582\*, 708, 722, 1033, 1322, 1323.
\:\\{font\_check}, \[549], 568, 602, 1322, 1323.
\:\9{font\_dimen\_}{\.{\\fontdimen} primitive}, \[265\*].
\:\\{font\_dsize}, 472, \[549], 552, 568, 602, 1260, 1261, 1322, 1323.
\:\\{font\_ec}, \[549], 552, 576, 582\*, 708, 722, 1033, 1322, 1323.
\:\\{font\_glue}, \[549], 552, 576, 578, 1042, 1322, 1323.
\:\\{font\_id\_base}, \[222], 234, 256, 415, 548, 1257.
\:\\{font\_id\_text}, \[256], 267, 579, 1257, 1322.
\:\\{font\_in\_short\_display}, \[173], 174\*, 193, 663\*, 864, 1339.
\:\\{font\_info}, 11\*, 425, 548, \[549], 550, 552, 554, 557, 558, 560, 566,
569, 571, 573, 574, 575, 578, 580, 700, 701, 713, 741, 752, 908, 1032, 1037,
1042, 1043, 1211, 1253, 1320, 1321, 1339.
\:\\{font\_max}, \[11\*], 111, 174\*, 176\*, 548, 551, 566, 1321, 1334.
\:\\{font\_mem\_size}, \[11\*], 549, 560, 566, 580, 906, 1032, 1043, 1211,
1321, 1334.
\:\\{font\_name}, 472, \[549], 552, 576, 581, 602, 603, 1260, 1261, 1322, 1323.
\:\9{font\_name\_}{\.{\\fontname} primitive}, \[468].
\:\\{font\_name\_code}, \[468], 469, 471, 472.
\:\\{font\_params}, \[549], 552, 576, 578, 579, 580, 1195, 1322, 1323.
\:\\{font\_ptr}, \[549], 552, 566, 576, 578, 643, 1260, 1320, 1321, 1334.
\:\\{font\_size}, 472, \[549], 552, 568, 602, 1260, 1261, 1322, 1323.
\:\\{font\_used}, \[549], 551, 621, 643.
\:\.{FONTx}, 1257.
\:\.{for accent}, 191.
\:\.{Forbidden control sequence...}, 338.
\:\\{force\_eof}, 331, \[361], 362, 378.
\:\\{form\_feed}, 27\*, \[30\*], 31\*, 71\*, 232\*, 363\*, 485\*, 538\*.
\:\\{format\_area\_length}, \[520\*], 523\*, 524.
\:\\{format\_default\_length}, \[520\*], 522, 523\*, 524.
\:\\{format\_ext\_length}, \[520\*], 523\*, 524.
\:\\{format\_ident}, 61, 536, \[1299], 1300, 1301, 1326, 1327, 1328, 1337.
\:\\{forward}, 78, 84\*, 218, 281, 340, 366\*, 409, 618, 692, 693, 720, 774,
800.
\:\\{found}, \[15], 125, 128, 129, 259, 341\*, 354, 356, 389, 392, 394, 448\*,
455, 473, 475, 477, 524, 607, 609, 612, 613, 614, 645, 706, 708, 720, 895, 923,
931, 934, 941, 953, 955, 1138, 1146, 1147\*, 1148, 1236, 1237.
\:\\{found1}, \[15], 895, 902, 1302, 1315.
\:\\{found2}, \[15], 1302, 1316.
\:\\{four\_choices}, \[113].
\:\\{four\_quarters}, \[113], 548, 549, 554, 555, 560, 649, 683, 684, 706, 709,
712, 724, 738, 906, 1032, 1123, 1302, 1303.
\:\\{fraction\_noad}, \[683], 687, 690, 698, 733, 761, 1178, 1181.
\:\\{fraction\_noad\_size}, \[683], 698, 761, 1181.
\:\\{fraction\_rule}, \[704], 705, 735, 747.
\:\\{free}, \[165], 167, 168, 169, 170, 171.
\:\\{free\_avail}, \[121], 202, 204, 217, 400, 772, 915, 939, 1226, 1288.
\:\\{free\_node}, \[130], 201, 202, 275, 496, 615, 655, 698, 715, 721, 727,
751, 753, 756, 760, 772, 803, 860, 861, 865, 977, 1019, 1021, 1022, 1100, 1110,
1186, 1187, 1201, 1358.
\:\\{freeze\_page\_specs}, \[987], 1001, 1008.
\:\\{frozen\_control\_sequence}, \[222], 258, 1215, 1314, 1318, 1319.
\:\\{frozen\_cr}, \[222], 339, 780, 1132.
\:\\{frozen\_dont\_expand}, \[222], 258, 369.
\:\\{frozen\_end\_group}, \[222], 265\*, 1065.
\:\\{frozen\_end\_template}, \[222], 375, 780.
\:\\{frozen\_endv}, \[222], 375, 380, 780.
\:\\{frozen\_fi}, \[222], 336\*, 491.
\:\\{frozen\_null\_font}, \[222], 553.
\:\\{frozen\_protection}, \[222], 1215, 1216.
\:\\{frozen\_relax}, \[222], 265\*, 372, 379.
\:\\{frozen\_right}, \[222], 1065, 1188.
\:{Fuchs, David Raymond}, 2\*, 37\*, 583, 591.
\:\9{future\_let\_}{\.{\\futurelet} primitive}, \[1219].
\:\|{g}, \[47], \[182], \[560], \[592], \[649], \[668], \[706], \[716].
\:\\{g\_order}, \[619], 625, \[629], 634.
\:\\{g\_sign}, \[619], 625, \[629], 634.
\:\\{garbage}, \[162], 467, 470, 1183, 1192, 1279.
\:\9{gdef\_}{\.{\\gdef} primitive}, \[1208].
\:\\{geq\_define}, \[279], 782, 1077, 1214.
\:\\{geq\_word\_define}, \[279], 288, 1013, 1214.
\:\\{get}, 26, 29, 31\*, 37\*, 485\*, 538\*, 564, 1306.
\:\\{get\_avail}, \[120], 122, 204, 205, 216, 325, 337, 339, 369, 371, 372,
473, 482, 582\*, 709, 772, 783, 784, 794, 907, 938, 1064, 1065, 1226, 1371.
\:\\{get\_next}, 76, 297, 332, 336\*, 340, \[341\*], 357, 360, 364, 365, 366\*,
369, 380, 381, 387, 389, 478, 494\*, 507, 644, 1036, 1126.
\:\\{get\_node}, \[125], 131, 136, 139, 144, 145, 147, 151, 152, 153, 156, 158,
206, 495, 607, 649, 668, 686, 688, 689, 716, 772, 798, 843, 844, 845, 864, 914,
1009, 1100, 1101, 1163, 1165, 1181, 1248, 1249, 1349, 1357.
\:\\{get\_preamble\_token}, \[782], 783, 784.
\:\\{get\_r\_token}, \[1215], 1218, 1221, 1224, 1225, 1257.
\:\\{get\_strings\_started}, \[47], 51, 1332.
\:\\{get\_token}, 76, 78, 88, 364, \[365], 368, 369, 392, 399, 442, 452, 471,
473, 474, 476, 477, 479, 483, 782, 1027, 1138, 1215, 1221, 1252, 1268, 1271,
1294, 1371, 1372.
\:\\{get\_x\_token}, 364, 366\*, 372, \[380], 381, 402, 404, 406, 407\*, 443,
444, 445, 452, 465, 479, 506, 526, 780, 935, 961, 1029, 1030, 1138, 1197, 1237,
1375.
\:\\{get\_x\_token\_or\_active\_char}, \[506].
\:\\{give\_err\_help}, 78, 89, 90, \[1284].
\:\\{global}, \[1214], 1218, 1241.
\:{global definitions}, 221, 279, 283.
\:\9{global\_}{\.{\\global} primitive}, \[1208].
\:\\{global\_defs}, \[236], 782, 1214, 1218.
\:\9{global\_defs\_}{\.{\\globaldefs} primitive}, \[238].
\:\\{global\_defs\_code}, \[236], 237, 238.
\:\\{glue\_base}, 220, \[222], 224, 226, 227, 228, 229, 252, 782.
\:\\{glue\_node}, \[149], 152, 153, 175, 183\*, 202, 206, 424, 622, 631, 651,
669, 730, 732, 761, 816, 817, 837, 856, 862, 866, 879, 881, 899\*, 968, 972,
973, 988, 996, 997, 1000, 1106, 1107, 1108, 1147\*, 1202.
\:\\{glue\_offset}, \[135], 159, 186.
\:\\{glue\_ord}, \[150], 447, 619, 629, 646, 649, 668, 791.
\:\\{glue\_order}, \[135], 136, 159, 185, 186, 619, 629, 657, 658, 664, 672,
673, 676, 769, 796, 801, 807, 809, 810, 811, 1148.
\:\\{glue\_par}, \[224], 766.
\:\\{glue\_pars}, \[224].
\:\\{glue\_ptr}, \[149], 152, 153, 175, 189, 190, 202, 206, 424, 625, 634, 656,
671, 679, 732, 786, 793, 795, 802, 803, 809, 816, 838, 869, 881, 969, 976, 996,
1001, 1004, 1148.
\:\\{glue\_ratio}, \[109], 110\*, 113, 135, 186.
\:\\{glue\_ref}, \[210], 228, 275, 782, 1228, 1236.
\:\\{glue\_ref\_count}, \[150], 151, 152, 153, 154, 164, 201, 203, 228, 766,
1043, 1060.
\:\\{glue\_set}, \[135], 136, 159, 186, 625, 634, 657, 658, 664, 672, 673, 676,
807, 809, 810, 811, 1148.
\:\\{glue\_shrink}, \[159], 185, 796, 799, 801, 810, 811.
\:\\{glue\_sign}, \[135], 136, 159, 185, 186, 619, 629, 657, 658, 664, 672,
673, 676, 769, 796, 801, 807, 809, 810, 811, 1148.
\:\\{glue\_spec\_size}, \[150], 151, 162, 164, 201, 716.
\:\\{glue\_stretch}, \[159], 185, 796, 799, 801, 810, 811.
\:\\{glue\_val}, \[410], 411, 412, 413, 416, 424, 427, 429, 430, 451, 461, 465,
782, 1060, 1228, 1236, 1237, 1238, 1240.
\:\.{goal height}, 986, 987.
\:\&{goto}, \[81].
\:\\{gr}, 110\*, \[113], 114, 135.
\:\\{group\_code}, \[269], 271, 274, 1136.
\:\&{gubed}, \[7\*].
\:{Guibas, Leonidas Ioannis}, 2\*.
\:\\{g1}, \[1198], 1203.
\:\\{g2}, \[1198], 1203, 1205.
\:\|{h}, \[204], \[259], \[649], \[668], \[738], \[929], \[934], \[944], %
\[947], \[949], \[953], \[960], \[970], \[977], \[994], \[1086], \[1123].
\:\\{h\_offset}, \[247], 617, 641.
\:\9{h\_offset\_}{\.{\\hoffset} primitive}, \[248].
\:\\{h\_offset\_code}, \[247], 248.
\:\\{ha}, \[892], 896\*, 900, 903.
\:\\{half}, \[100], 706, 736, 737, 738, 745, 746, 749, 750, 1202.
\:\\{half\_buf}, 594\*, \[595\*], 596, 598, 599.
\:\\{half\_error\_line}, \[11\*], 14, 311, 315, 316, 317.
\:\\{halfword}, 108, 110\*, \[113], 115, 130, 264, 277, 279, 280, 281, 297,
298, 300, 333, 341\*, 366\*, 389, 413, 464, 473, 549, 560, 577, 681, 791, 800,
821, 829, 830, 833, 847, 872, 877, 892, 1032, 1079, 1211, 1243, 1266, 1288.
\:\\{halign}, \[208\*], 265\*, 266\*, 1094, 1130.
\:\9{halign\_}{\.{\\halign} primitive}, \[265\*].
\:\\{handle\_right\_brace}, 1067, \[1068\*].
\:\\{hang\_after}, \[236], 240, 847, 849, 1070, 1149.
\:\9{hang\_after\_}{\.{\\hangafter} primitive}, \[238].
\:\\{hang\_after\_code}, \[236], 237, 238, 1070.
\:\\{hang\_indent}, \[247], 847, 848, 849, 1070, 1149.
\:\9{hang\_indent\_}{\.{\\hangindent} primitive}, \[248].
\:\\{hang\_indent\_code}, \[247], 248, 1070.
\:{hanging indentation}, 847.
\:\\{hash}, 234, \[256], 257, 259, 260, 1318, 1319.
\:\\{hash\_base}, 220, \[222], 256, 257, 259, 262, 263, 1257, 1314, 1318, 1319.
\:\\{hash\_brace}, \[473], 476.
\:\\{hash\_is\_full}, \[256], 260.
\:\\{hash\_prime}, \[12\*], 14, 259, 261, 1307, 1308.
\:\\{hash\_size}, \[12\*], 14, 222, 260, 261, 1334.
\:\\{hash\_used}, \[256], 258, 260, 1318, 1319.
\:\\{hb}, \[892], 897, 898, 900, 903.
\:\\{hbadness}, \[236], 658, 660, 664, 666, 667.
\:\9{hbadness\_}{\.{\\hbadness} primitive}, \[238].
\:\\{hbadness\_code}, \[236], 237, 238.
\:\9{hbox\_}{\.{\\hbox} primitive}, \[1071].
\:\\{hbox\_group}, \[269], 274, 1083, 1085.
\:\\{hc}, \[892], 893, 897, 898, 900, 901, 919, 920, 923, 930, 931, 934, 937,
939, 960, 962, 963, 965.
\:\\{hd}, \[649], 654\*, \[706], 708, \[709], \[712].
\:\\{head}, 212, \[213], 215, 216, 217, 424, 718, 776, 796, 799, 805, 812, 814,
816, 1026, 1054, 1080, 1081, 1086, 1091, 1096, 1100, 1105, 1113, 1119, 1121,
1145, 1159, 1168, 1176, 1181, 1184, 1185, 1187, 1191.
\:\\{head\_field}, \[212], 213, 218.
\:\\{head\_for\_vmode}, 1094, \[1095].
\:\\{header}, 542.
\:{Hedrick, Charles Locke}, 3.
\:\\{height}, \[135], 136, 138, 139, 140, 184, 187, 188, 463, 554, 622, 624,
626, 629, 631, 632, 635, 637, 640, 641, 649, 653, 656, 670, 672, 679, 704, 706,
709, 711, 713, 727, 730, 735, 736, 737, 738, 739, 742, 745, 746, 747, 749, 750,
751, 756, 757, 759, 768, 769, 796, 801, 804, 806, 807, 809, 810, 811, 969, 973,
\[981], 986, 1001, 1002, 1008, 1009, 1010, 1021, 1087, 1100.
\:\.{height}, 463.
\:\\{height\_base}, \[550], 552, 554, 566, 571, 1322, 1323.
\:\\{height\_depth}, \[554], 654\*, 708, 709, 712, 1125\*.
\:\\{height\_index}, \[543], 554.
\:\\{height\_offset}, \[135], 416, 417, 769, 1247.
\:\\{height\_plus\_depth}, \[712], 714.
\:\.{held over for next output}, 986.
\:\\{help\_line}, \[79], 89, 90, 336\*, 1106.
\:\\{help\_ptr}, \[79], 80, 89, 90.
\:\\{help0}, \[79], 1252, 1293.
\:\\{help1}, \[79], 93, 95, 288, 408, 428, 454, 476, 486, 500, 503, 510, 961,
962, 963, 1066, 1080, 1099, 1121, 1132, 1135, 1159, 1177, 1192, 1212, 1213,
1232, 1237, 1243, 1244, 1258, 1283, 1304.
\:\\{help2}, 72, \[79], 88, 89, 94, 95, 288, 346, 373, 432, 433, 434, 435\*,
436, 437, 442, 445, 460, 475, 476, 577, 579, 641, 936, 937, 978, 1015, 1027,
1047, 1068\*, 1080, 1082, 1095, 1106, 1120, 1129, 1166, 1197, 1207, 1225, 1236,
1259, 1372.
\:\\{help3}, 72, \[79], 98, 336\*, 396, 415, 446, 479, 776, 783, 784, 792, 993,
1009, 1024, 1028, 1078, 1084, 1110, 1127, 1183, 1195, 1293.
\:\\{help4}, \[79], 89, 338, 398, 403, 418, 456, 567, 723, 976, 1004, 1050,
1283.
\:\\{help5}, \[79], 370, 561, 826, 1064, 1069, 1128, 1215, 1293.
\:\\{help6}, \[79], 395, 459, 1128, 1161.
\:\.{Here is how much...}, 1334.
\:\\{hex\_token}, \[438], 444.
\:\\{hf}, \[892], 896\*, 897, 898, 905, 907, 908, 910, 915, 918.
\:\9{hfil\_}{\.{\\hfil} primitive}, \[1058].
\:\9{hfil\_neg\_}{\.{\\hfilneg} primitive}, \[1058].
\:\9{hfill\_}{\.{\\hfill} primitive}, \[1058].
\:\\{hfuzz}, \[247], 666.
\:\9{hfuzz\_}{\.{\\hfuzz} primitive}, \[248].
\:\\{hfuzz\_code}, \[247], 248.
\:\\{hh}, 110\*, \[113], 114, 118, 133, 182, 221, 268, 686, 742, 1163, 1165,
1181, 1186, 1305, 1306.
\:\\{hi}, \[112\*], 232\*, 1232.
\:\\{hi\_mem\_base}, 12\*.
\:\\{hi\_mem\_min}, \[116\*], 118, 120, 125, 126, 134\*, 164, 165, 167, 168,
171, 172, 176\*, 293, 639, 1311, 1312, 1334.
\:\\{hi\_mem\_stat\_min}, \[162], 164, 1312.
\:\\{hi\_mem\_stat\_usage}, \[162], 164.
\:\\{history}, \[76], 77, 82, 93, 95, 245, 535, 1332, 1335\*.
\:\\{hlist\_node}, \[135], 136, 137, 138, 148, 159, 175, 183\*, 184, 202, 206,
505, 618, 619, 622, 631, 644, 649, 651, 669, 681, 807, 810, 814, 841\*, 842\*,
866, 871\*, 968, 973, 993, 1000, 1074, 1080, 1087, 1110, 1147\*, 1203.
\:\\{hlist\_out}, 592, 615, 616, 618, \[619], 620\*, 623, 628, 629, 632, 637,
638, 640, 693, 1373.
\:\\{hlp1}, \[79].
\:\\{hlp2}, \[79].
\:\\{hlp3}, \[79].
\:\\{hlp4}, \[79].
\:\\{hlp5}, \[79].
\:\\{hlp6}, \[79].
\:\\{hmode}, \[211], 416, 501, 786, 787, 796, 799, 1030, 1039, 1045, 1046\*,
1048, 1056, 1057, 1071, 1073, 1076, 1079, 1083, 1086, 1091, 1092, 1093, 1094,
1096, 1097, 1109, 1110, 1112, 1116, 1117, 1119, 1122\*, 1130, 1137, 1200, 1243.
\:\\{hmove}, \[208\*], 1048, 1071, 1072, 1073.
\:\\{hn}, \[892], 897, 898, 899\*, 902, 912, 913, 915, 916, 919, 923, 930, 931.
\:\\{ho}, \[112\*], 235, 414, 1151, 1154.
\:\\{hold\_head}, \[162], 306, 779, 783, 784, 794, 808, 905, 907, 910, 911,
913, 914, 915, 916, 1014, 1017.
\:\\{hpack}, 162, 236, 644, 645, 646, 647, \[649], 661, 709, 715, 720, 727,
737, 748, 754, 756, 796, 799, 804, 889, 1062, 1086, 1125\*, 1194, 1199, 1201,
1204.
\:\\{hrule}, \[208\*], 265\*, 266\*, 463, 1046\*, 1056, 1084, 1094, 1095.
\:\9{hrule\_}{\.{\\hrule} primitive}, \[265\*].
\:\\{hsize}, \[247], 847, 848, 849, 1054, 1149.
\:\9{hsize\_}{\.{\\hsize} primitive}, \[248].
\:\\{hsize\_code}, \[247], 248.
\:\\{hskip}, \[208\*], 1057, 1058, 1059, 1078, 1090\*.
\:\9{hskip\_}{\.{\\hskip} primitive}, \[1058].
\:\9{hss\_}{\.{\\hss} primitive}, \[1058].
\:\9{ht\_}{\.{\\ht} primitive}, \[416].
\:\\{hu}, \[892], 893, 897, 898, 901, 905, 907, 908, 912, 915.
\:\.{Huge page...}, 641.
\:\\{hyf}, \[900], 902, 905, 908, 913, 915, 916, 919, 920, 923, 924, 932, 960,
961, 962, 963, 965.
\:\\{hyf\_char}, \[892], 896\*, 915, 918.
\:\\{hyf\_distance}, 920, \[921], 922, 924, 943, 944, 960, 1324, 1325.
\:\\{hyf\_next}, 920, \[921], 924, 943, 944, 960, 1324, 1325.
\:\\{hyf\_node}, \[912], 915.
\:\\{hyf\_num}, 920, \[921], 924, 943, 944, 960, 1324, 1325.
\:\\{hyph\_count}, \[926], 928, 940, 1324, 1325, 1334.
\:\\{hyph\_data}, \[209\*], 1210, 1250, 1251, 1252.
\:\\{hyph\_list}, \[926], 928, 929, 932, 933, 934, 940, 941, 1324, 1325.
\:\\{hyph\_pointer}, \[925], 926, 927, 929, 934.
\:\\{hyph\_size}, \[12\*], 925, 928, 930, 933, 939, 940, 1307, 1308, 1324,
1325, 1334.
\:\\{hyph\_word}, \[926], 928, 929, 931, 934, 940, 941, 1324, 1325.
\:\\{hyphen\_char}, 426, \[549], 552, 576, 891, 896\*, 1039, 1117, 1253, 1322,
1323.
\:\9{hyphen\_char\_}{\.{\\hyphenchar} primitive}, \[1254].
\:\\{hyphen\_passed}, \[905], 907, 908, 913, 914.
\:\\{hyphen\_penalty}, 145, \[236], 870.
\:\9{hyphen\_penalty\_}{\.{\\hyphenpenalty} primitive}, \[238].
\:\\{hyphen\_penalty\_code}, \[236], 237, 238.
\:\\{hyphenate}, 894, \[895].
\:\\{hyphenated}, \[819], 820, 829, 846, 859, 870, 873.
\:\.{Hyphenation trie...}, 1324.
\:\9{hyphenation\_}{\.{\\hyphenation} primitive}, \[1250].
\:\|{i}, \[19], \[315], \[530\*], \[587], \[649], \[738], \[901], \[1032], %
\[1123], \[1348].
\:\.{I can't find file x}, 530\*.
\:\.{I can't find PLAIN...}, 524.
\:\.{I can't go on...}, 95.
\:\.{I can't read TEX.POOL}, 51.
\:\.{I can't write on file x}, 530\*, 535.
\:\\{id\_byte}, \[587], 617, 642\*.
\:\\{id\_lookup}, \[259], 264, 356, 374.
\:\\{ident\_val}, \[410], 415, 465, 466.
\:\9{if\_case\_}{\.{\\ifcase} primitive}, \[487].
\:\\{if\_case\_code}, \[487], 488, 501.
\:\\{if\_cat\_code}, \[487], 488, 501.
\:\9{if\_cat\_code\_}{\.{\\ifcat} primitive}, \[487].
\:\9{if\_char\_}{\.{\\if} primitive}, \[487].
\:\\{if\_char\_code}, \[487], 501, 506.
\:\\{if\_code}, \[489], 495, 510.
\:\9{if\_dim\_}{\.{\\ifdim} primitive}, \[487].
\:\\{if\_dim\_code}, \[487], 488, 501.
\:\9{if\_eof\_}{\.{\\ifeof} primitive}, \[487].
\:\\{if\_eof\_code}, \[487], 488, 501.
\:\9{if\_false\_}{\.{\\iffalse} primitive}, \[487].
\:\\{if\_false\_code}, \[487], 488, 501.
\:\9{if\_hbox\_}{\.{\\ifhbox} primitive}, \[487].
\:\\{if\_hbox\_code}, \[487], 488, 501, 505.
\:\9{if\_hmode\_}{\.{\\ifhmode} primitive}, \[487].
\:\\{if\_hmode\_code}, \[487], 488, 501.
\:\9{if\_inner\_}{\.{\\ifinner} primitive}, \[487].
\:\\{if\_inner\_code}, \[487], 488, 501.
\:\9{if\_int\_}{\.{\\ifnum} primitive}, \[487].
\:\\{if\_int\_code}, \[487], 488, 501, 503.
\:\\{if\_limit}, \[489], 490, 495, 496, 497, 498, 510.
\:\\{if\_line}, \[489], 490, 495, 496, 1335\*.
\:\\{if\_line\_field}, \[489], 495, 496, 1335\*.
\:\9{if\_mmode\_}{\.{\\ifmmode} primitive}, \[487].
\:\\{if\_mmode\_code}, \[487], 488, 501.
\:\\{if\_node\_size}, \[489], 495, 496.
\:\9{if\_odd\_}{\.{\\ifodd} primitive}, \[487].
\:\\{if\_odd\_code}, \[487], 488, 501.
\:\\{if\_test}, \[210], 336\*, 366\*, 367, 487, 488, 494\*, 498, 503, 1335\*.
\:\9{if\_true\_}{\.{\\iftrue} primitive}, \[487].
\:\\{if\_true\_code}, \[487], 488, 501.
\:\9{if\_vbox\_}{\.{\\ifvbox} primitive}, \[487].
\:\\{if\_vbox\_code}, \[487], 488, 501.
\:\9{if\_vmode\_}{\.{\\ifvmode} primitive}, \[487].
\:\\{if\_vmode\_code}, \[487], 488, 501.
\:\9{if\_void\_}{\.{\\ifvoid} primitive}, \[487].
\:\\{if\_void\_code}, \[487], 488, 501, 505.
\:\9{ifx\_}{\.{\\ifx} primitive}, \[487].
\:\\{ifx\_code}, \[487], 488, 501.
\:\\{ignore}, \[207], 232\*, 332, 345.
\:\\{ignore\_depth}, \[212], 215, 219, 679, 787, 1025, 1056, 1083, 1099, 1167.
\:\\{ignore\_spaces}, \[208\*], 265\*, 266\*, 1045.
\:\9{ignore\_spaces\_}{\.{\\ignorespaces} primitive}, \[265\*].
\:\.{Illegal magnification...}, 288, 1258.
\:\.{Illegal math \\disc...}, 1120.
\:\.{Illegal parameter number...}, 479.
\:\.{Illegal unit of measure}, 454, 456, 459.
\:\9{immediate\_}{\.{\\immediate} primitive}, \[1344].
\:\\{immediate\_code}, \[1344], 1346, 1348.
\:\.{IMPOSSIBLE}, 262.
\:\.{Improper \\halign...}, 776.
\:\.{Improper \\hyphenation...}, 936.
\:\.{Improper \\prevdepth}, 418.
\:\.{Improper \\spacefactor}, 418.
\:\.{Improper `at' size...}, 1259.
\:\.{Improper alphabetic constant}, 442.
\:\.{Improper discretionary list}, 1121.
\:\.{in}, 458.
\:\\{in\_open}, \[304\*], 328\*, 329\*, 331.
\:\\{in\_state\_record}, \[300], 301.
\:\\{in\_stream}, \[208\*], 1272, 1273, 1274.
\:\.{Incompatible glue units}, 408.
\:\.{Incompatible list...}, 1110.
\:\.{Incompatible magnification}, 288.
\:\\{incompleat\_noad}, 212, \[213], 718, 776, 1136, 1178, 1181, 1182, 1184,
1185.
\:\.{Incomplete \\if...}, 336\*.
\:\\{incr}, \[16], 31\*, 37\*, 42, 43, 45, 46, 53, 58, 59, 60, 65, 67, 70, 71%
\*, 82, 84\*, 90, 98, 120, 122, 152, 153, 170, 182, 203, 216, 260, 274, 276,
280, 294, 321, 325, 328\*, 343, 347, 354, 355, 356, 357, 360, 362, 363\*, 366%
\*, 374, 392, 395, 397, 399, 400, 403, 407\*, 440\*, 442, 448\*, 452, 454, 464,
475, 476, 477, 494\*, 517\*, 519\*, 524, 531, 580, 598, 619, 629, 640, 714,
741, 752, 798, 842\*, 845, 877, 897, 898, 908, 909, 915, 917, 923, 931, 937,
940, 941, 944, 954, 958, 962, 963, 964, 986, 1022, 1025, 1037, 1063\*, 1069,
1083, 1099, 1117, 1119, 1121, 1127, 1142, 1153, 1172, 1174, 1315, 1316, 1318,
1337.
\:\9{indent\_}{\.{\\indent} primitive}, \[1088].
\:\\{indent\_in\_hmode}, 1092, \[1093].
\:\\{indented}, \[1091].
\:\\{index}, 300, \[302], 303, 304\*, 307, 328\*, 329\*, 331.
\:\\{index\_field}, \[300], 302.
\:\\{inf}, 447, \[448\*], 453.
\:\\{inf\_bad}, \[108], 157, 658, 673, 851, 852, 853, 974, 1005, 1017.
\:\\{inf\_penalty}, \[157], 761, 767, 816, 829, 831, 974, 1005, 1013, 1203,
1205.
\:\.{Infinite glue shrinkage...}, 826, 976, 1004, 1009.
\:\\{infinity}, \[445].
\:\\{info}, \[118], 124, 126, 140, 164, 172, 200, 233, 275, 291, 293, 325, 337,
339, 357, 358, 369, 371, 374, 389, 391, 392, 393, 394, 397, 400, 423, 466, 508,
605, 608, 609, 610, 611, 612, 613, 614, 615, 681, 689, 692, 693, 698, 720, 734,
735, 736, 737, 738, 742, 749, 754, 768, 769, 772, 779, 783, 784, 790, 793, 794,
797, 798, 801, 803, 821, 847, 848, 925, 932, 938, 939, 981, 1065, 1076, 1093,
1149, 1151, 1168, 1181, 1185, 1186, 1191, 1226, 1248, 1249, 1289, 1312, 1339,
1341, 1371.
\:\&{init}, \[8\*], \[47], \[50], \[131], \[264], \[942], \[943], \[945], %
\[946], \[950], \[1252], \[1302], \[1332], \[1335\*], \[1336].
\:\\{init\_align}, 773, \[774], 1130.
\:\\{init\_col}, 773, 785, \[788], 791.
\:\\{init\_math}, 1137, \[1138].
\:\\{init\_pattern\_memory}, \[949], 960.
\:\\{init\_pool\_ptr}, \[39], 42, 1332, 1334.
\:\\{init\_prim}, 1332, \[1336].
\:\\{init\_row}, 773, 785, \[786].
\:\\{init\_span}, 773, 786, \[787], 791.
\:\\{init\_str\_ptr}, \[39], 43, 517\*, 1332, 1334.
\:\\{init\_terminal}, \[37\*], 331.
\:\\{init\_trie\_memory}, \[951], 966.
\:\.{INITEX}, 8\*, 11\*, 12\*, 47, 50, 116\*, 1299, 1331.
\:\\{initialize}, \[4], 1332, 1337.
\:{inner loop}, 31\*, 112\*, 120, 121, 122, 123, 125, 127, 128, 130, 202, 324,
325, 341\*, 342, 343, 357, 365, 380, 399, 407\*, 554, 597\*, 611, 620\*, 651,
654\*, 832, 835, 851, 852, 867\*, 1035, 1036, 1037.
\:\\{inner\_noad}, \[682], 683, 690, 696, 698, 733, 761, 764, 1156, 1157, 1191.
\:\\{input}, \[210], 366\*, 367, 376, 377.
\:\9{input\_}{\.{\\input} primitive}, \[376].
\:\\{input\_file}, \[304\*].
\:\\{input\_ln}, 30\*, \[31\*], 37\*, 58, 71\*, 362, 363\*, 485\*, 486, 538\*.
\:\\{input\_ptr}, \[301], 311, 312, 321, 322, 330, 331, 360, 534.
\:\\{input\_stack}, 84\*, \[301], 311, 321, 322, 534.
\:\\{ins\_error}, \[327], 336\*, 395, 1047, 1127, 1132, 1215.
\:\\{ins\_list}, \[323], 339, 467, 470, 1064, 1371.
\:\\{ins\_node}, \[140], 148, 175, 183\*, 202, 206, 647, 651, 730, 761, 866,
899\*, 968, 973, 981, 986, 1000, 1014, 1100.
\:\\{ins\_node\_size}, \[140], 202, 206, 1022, 1100.
\:\\{ins\_ptr}, \[140], 188, 202, 206, 1010, 1020, 1021, 1100.
\:\\{ins\_the\_toks}, 366\*, 367, \[467].
\:\\{insert}, \[208\*], 265\*, 266\*, 1097.
\:\.{insert>}, 87.
\:\9{insert\_}{\.{\\insert} primitive}, \[265\*].
\:\\{insert\_dollar\_sign}, 1045, \[1047].
\:\\{insert\_group}, \[269], 1068\*, 1099, 1100.
\:\\{insert\_penalties}, 419, \[982], 990, 1005, 1008, 1010, 1014, 1022, 1026,
1242, 1246.
\:\9{insert\_penalties\_}{\.{\\insertpenalties} primitive}, \[416].
\:\\{insert\_relax}, 378, \[379], 510.
\:\\{insert\_token}, \[268], 280, 282.
\:\\{inserted}, \[307], 314, 323, 324, 327, 379, 1095.
\:\\{inserting}, \[981], 1009.
\:\.{Insertions can only...}, 993.
\:\\{inserts\_only}, \[980], 987, 1008.
\:\\{inskp0}, \[34\*].
\:\\{int}, 110\*, \[113], 114, 140, 141, 157, 186, 236, 240, 242, 274, 278,
279, 413, 414, 489, 605, 725, 769, 772, 819, 1238, 1240, 1305, 1306, 1308, 1316.
\:\\{int\_base}, 220, \[230], 232\*, 236, 238, 239, 240, 242, 252, 253, 254,
268, 283, 288, 1013, 1070, 1139, 1145, 1315.
\:\\{int\_error}, \[91], 288, 432, 433, 434, 435\*, 436, 437, 1243, 1244, 1258.
\:\\{int\_par}, \[236].
\:\\{int\_pars}, \[236].
\:\\{int\_val}, \[410], 411, 412, 413, 414, 416, 417, 418, 419, 422, 423, 424,
426, 427, 428, 429, 439, 440\*, 449, 461, 465, 1236, 1237, 1238.
\:\\{integer}, 3, 13, 27\*, 31\*, 37\*, 45, 47, 54, 59, 60, 63, 65, 66, 67, 68,
69, 82, 91, 94, 96, 100, 101, 102, 105, 106, 107, 108, 109, 110\*, 113, 117,
125, 158, 163, 172, 173, 174\*, 176\*, 177, 178, 181, 182, 211, 212, 218, 225,
237, 241\*, 247, 256, 259, 262, 278, 279, 286, 292, 304\*, 308, 309, 315, 366%
\*, 410, 440\*, 448\*, 450, 482, 489, 493\*, 494\*, 498, 518\*, 519\*, 523\*,
549, 550, 560, 578, 582\*, 592, 595\*, 597\*, 600, 601, 607, 615, 616, 619,
629, 638, 649, 661, 668, 691, 694, 699, 706, 716, 717, 726, 738, 752, 764, 815,
828, 829, 830, 872, 877, 892, 970, 980, 982, 994, 1012, 1030, 1032, 1068\*,
1117, 1119, 1138, 1151, 1155, 1194, 1211, 1302, 1303, 1331, 1333\*, 1338, 1348,
1370, 1379\*.
\:\\{inter\_line\_penalty}, \[236], 890.
\:\9{inter\_line\_penalty\_}{\.{\\interlinepenalty} primitive}, \[238].
\:\\{inter\_line\_penalty\_code}, \[236], 237, 238.
\:\\{interaction}, 71\*, 72, \[73], 74, 75, 82, 84\*, 86, 90, 92, 93, 98, 360,
363\*, 484, 530\*, 535, 1265, 1283, 1293, 1294, 1297, 1326, 1327, 1328, 1333\*,
1335\*.
\:\\{internal\_font\_number}, \[548], 549, 550, 560, 577, 578, 581, 582\*, 602,
616, 649, 706, 709, 711, 712, 715, 724, 738, 830, 862, 892, 1032, 1043, 1113,
1123, 1138, 1211, 1257.
\:\\{interrupt}, 37\*, \[96], 97, 98, 1031.
\:\.{Interruption}, 98.
\:\.{interwoven alignment preambles...}, 789.
\:\.{Invalid code}, 1232.
\:\\{invalid\_char}, \[207], 232\*, 344.
\:\\{invalid\_code}, \[22], 24, 232\*.
\:\\{is\_char\_node}, \[134\*], 174\*, 183\*, 202, 205, 424, 620\*, 630, 651,
669, 715, 720, 721, 756, 816, 837, 841\*, 842\*, 866, 867\*, 868, 871\*, 879,
883, 896\*, 897, 899\*, 1080, 1081, 1105, 1113, 1121, 1147\*.
\:\\{is\_empty}, \[124], 127, 169, 170.
\:\\{is\_running}, \[138], 176\*, 624, 633, 806.
\:\\{is\_xchar\_node}, \[134\*], 174\*, 176\*, 620\*, 841\*, 896\*, 899\*, 1125%
\*.
\:\\{issue\_message}, 1276, \[1279].
\:\\{ital\_corr}, \[208\*], 265\*, 266\*, 1111, 1112.
\:{italic correction}, \[543].
\:\\{italic\_base}, \[550], 552, 554, 566, 571, 1322, 1323.
\:\\{italic\_index}, \[543].
\:\\{its\_all\_over}, 1045, \[1054], 1335\*.
\:\|{j}, \[45], \[46], \[59], \[60], \[69], \[70], \[259], \[264], \[315], %
\[366\*], \[519\*], \[523\*], \[524], \[638], \[893], \[901], \[906], \[934], %
\[1032], \[1211], \[1302], \[1303], \[1348], \[1370], \[1373].
\:{Japanese characters}, 134\*, 585.
\:{Jensen, Kathleen}, 10.
\:\.{job aborted}, 360.
\:\.{job aborted, file error...}, 530\*.
\:\\{job\_name}, 92, 471, 472, \[527], 528, 529, 532, 534, 535, 537, 1257,
1265, 1328, 1333\*, 1334, 1335\*.
\:\9{job\_name\_}{\.{\\jobname} primitive}, \[468].
\:\\{job\_name\_code}, \[468], 470, 471, 472.
\:\\{jump\_out}, \[81], 82, 84\*, 93, 535.
\:\\{just\_box}, \[814], 888, 889, 1146, 1148.
\:\\{just\_open}, \[480], 483, 1275.
\:\|{k}, \[31\*], \[45], \[46], \[47], \[64], \[65], \[67], \[69], \[71\*], %
\[102], \[163], \[259], \[264], \[341\*], \[363\*], \[407\*], \[450], \[464], %
\[519\*], \[523\*], \[525\*], \[530\*], \[534], \[560], \[587], \[602], \[607],
\[638], \[705], \[929], \[934], \[960], \[1032], \[1043], \[1079], \[1211], %
\[1302], \[1303], \[1333\*], \[1338], \[1348], \[1368].
\:\\{kern}, \[208\*], \[545], 1057, 1058, 1059.
\:\9{kern\_}{\.{\\kern} primitive}, \[1058].
\:\\{kern\_base}, \[550], 552, 557, 566, 573, 576, 1322, 1323.
\:\\{kern\_break}, \[866].
\:\\{kern\_flag}, \[545], 741, 753, 908, 1037.
\:\\{kern\_node}, \[155], 156, 183\*, 202, 206, 424, 622, 631, 651, 669, 721,
730, 732, 761, 837, 841\*, 842\*, 856, 866, 871\*, 879, 881, 896\*, 897, 899\*,
968, 972, 973, 976, 996, 997, 1000, 1004, 1106, 1107, 1108, 1121, 1147\*.
\:{Knuth, Donald Ervin}, 2\*, 30\*, 86, 693, 813, 891, 925, 997, 1154, 1371.
\:\|{l}, \[37\*], \[47], \[259], \[264], \[276], \[281], \[292], \[315], \[494%
\*], \[497], \[534], \[601], \[615], \[668], \[830], \[901], \[960], \[1032], %
\[1138], \[1194], \[1236], \[1302], \[1338].
\:\\{large\_attempt}, \[706].
\:\\{large\_char}, \[683], 691, 697, 706, 1160.
\:\\{large\_fam}, \[683], 691, 697, 706, 1160.
\:\\{last}, \[30\*], 31\*, 36, 37\*, 71\*, 83, 87, 88, 331, 360, 363\*, 483,
485\*, 524, 531, 538\*.
\:\\{last\_active}, \[819], 820, 832, 835, 844, 854, 860, 861, 863, 864, 865,
873, 874, 875.
\:\\{last\_bop}, \[592], 593, 640, 642\*.
\:\9{last\_box\_}{\.{\\lastbox} primitive}, \[1071].
\:\\{last\_box\_code}, \[1071], 1072, 1079.
\:\\{last\_glue}, 424, \[982], 991, 996, 1017, 1106.
\:\\{last\_ins\_ptr}, \[981], 1005, 1008, 1018, 1020.
\:\\{last\_item}, \[208\*], 413, 416, 417, 1048.
\:\\{last\_kern}, 424, \[982], 991, 996.
\:\9{last\_kern\_}{\.{\\lastkern} primitive}, \[416].
\:\\{last\_penalty}, 424, \[982], 991, 996.
\:\9{last\_penalty\_}{\.{\\lastpenalty} primitive}, \[416].
\:\9{last\_skip\_}{\.{\\lastskip} primitive}, \[416].
\:\\{last\_special\_line}, \[847], 848, 849, 850, 889.
\:\\{last\_text\_char}, \[19], 24.
\:\\{lc\_code}, \[230], 232\*, 891, 896\*, 897, 898, 937, 962.
\:\9{lc\_code\_}{\.{\\lccode} primitive}, \[1230].
\:\\{lc\_code\_base}, \[230], 235, 1230, 1231, 1286, 1287, 1288.
\:\\{leader\_box}, \[619], 626, 628, \[629], 635, 637.
\:\\{leader\_flag}, \[1071], 1073, 1078, 1084.
\:\\{leader\_ht}, \[629], 635, 636, 637.
\:\\{leader\_ptr}, \[149], 152, 153, 190, 202, 206, 626, 635, 656, 671, 816,
1078.
\:\\{leader\_ship}, \[208\*], 1071, 1072, 1073.
\:\\{leader\_wd}, \[619], 626, 627, 628.
\:{leaders}, 1374.
\:\.{Leaders not followed by...}, 1078.
\:\9{leaders\_}{\.{\\leaders} primitive}, \[1071].
\:\\{least\_cost}, \[970], 974, 980.
\:\\{least\_page\_cost}, \[980], 987, 1005, 1006.
\:\9{left\_}{\.{\\left} primitive}, \[1188].
\:\\{left\_brace}, \[207], 289, 294, 298, 347, 357, 403, 473, 476, 777, 1063\*,
1150, 1226.
\:\\{left\_brace\_limit}, \[289], 325, 392, 394, 399.
\:\\{left\_brace\_token}, \[289], 403, 1127, 1226, 1371.
\:\\{left\_delimiter}, \[683], 696, 697, 737, 748, 1163, 1181, 1182.
\:\\{left\_edge}, \[619], 627, \[629], 632, 637.
\:\\{left\_noad}, \[687], 690, 696, 698, 725, 728, 733, 760, 761, 762, 1185,
1188, 1189, 1191.
\:\\{left\_right}, \[208\*], 1046\*, 1188, 1189, 1190.
\:\\{left\_skip}, \[224], 827, 880, 887.
\:\9{left\_skip\_}{\.{\\leftskip} primitive}, \[226].
\:\\{left\_skip\_code}, \[224], 225, 226, 887.
\:\\{length}, \[40], 46, 259, 537, 602, 931, 941, 1280.
\:{length of lines}, 847.
\:\9{leq\_no\_}{\.{\\leqno} primitive}, \[1141].
\:\\{let}, \[209\*], 1210, 1219, 1220, 1221.
\:\9{let\_}{\.{\\let} primitive}, \[1219].
\:\\{letter}, \[207], 232\*, 262, 289, 291, 294, 298, 347, 354, 356, 935, 961,
1029, 1030, 1036, 1090\*, 1124\*, 1151, 1154, 1160.
\:\\{letter\_token}, \[289], 445.
\:\\{level}, 410, \[413], 415, 418, 428, \[461].
\:\\{level\_boundary}, \[268], 270, 274, 282.
\:\\{level\_one}, \[221], 228, 232\*, 254, 264, 272, 277, 278, 279, 281, 283,
780, 1304, 1335\*, 1369.
\:\\{level\_zero}, \[221], 222, 272, 276, 280.
\:\\{lf}, 540, \[560], 565, 566, 575, 576.
\:\\{lh}, 110\*, \[113], 114, 118, 256, 540, 541, \[560], 565, 566, 568, 685,
950.
\:{Liang, Franklin Mark}, 2\*, 919.
\:\\{lig\_char}, \[143], 144, 193, 206, 652, 841\*, 842\*, 866, 871\*, 1113.
\:\\{lig\_kern}, 544, 545.
\:\\{lig\_kern\_base}, \[550], 552, 557, 566, 571, 573, 576, 1322, 1323.
\:\\{lig\_kern\_command}, 541, \[545].
\:\\{lig\_kern\_start}, \[557], 741, 752, 908, 1037.
\:\\{lig\_ptr}, \[143], 144, 175, 193, 202, 206, 896\*, 898.
\:\\{lig\_tag}, \[544], 569, 741, 752, 908, 1036.
\:\\{lig\_trick}, \[162], 652.
\:\\{ligature\_node}, \[143], 144, 148, 175, 183\*, 202, 206, 622, 651, 752,
841\*, 842\*, 866, 871\*, 896\*, 897, 899\*, 1113, 1121, 1147\*.
\:\\{ligature\_present}, \[1032], 1033, 1039, 1040.
\:\\{limit}, 300, \[302], 303, 307, 318, 328\*, 330, 331, 343, 348, 350, 351,
352, 354, 355, 356, 360, 362, 363\*, 483, 537, 538\*, 1337.
\:\.{Limit controls must follow...}, 1159.
\:\\{limit\_field}, 87, \[300], 302, 534.
\:\\{limit\_switch}, \[208\*], 1046\*, 1156, 1157, 1158.
\:\\{limits}, \[682], 696, 733, 749, 1156, 1157.
\:\9{limits\_}{\.{\\limits} primitive}, \[1156].
\:\\{line}, 31\*, 84\*, 216, \[304\*], 313\*, 328\*, 329\*, 331, 362, 494\*,
495, 538\*, 663\*, 675\*, 1025, 1063\*.
\:\\{line\_break}, 162, 814, \[815], 828, 839, 848, 862, 863, 866, 876, 894,
934, 967, 970, 982, 1096, 1145.
\:\\{line\_diff}, \[872], 875.
\:\\{line\_feed}, 31\*.
\:\\{line\_found}, \[37\*].
\:\\{line\_number}, \[819], 820, 833, 835, 845, 846, 850, 864, 872, 874, 875.
\:\\{line\_penalty}, \[236], 859.
\:\9{line\_penalty\_}{\.{\\linepenalty} primitive}, \[238].
\:\\{line\_penalty\_code}, \[236], 237, 238.
\:\\{line\_skip}, \[224], 247.
\:\9{line\_skip\_}{\.{\\lineskip} primitive}, \[226].
\:\\{line\_skip\_code}, 149, 152, \[224], 225, 226, 679.
\:\\{line\_skip\_limit}, \[247], 679.
\:\9{line\_skip\_limit\_}{\.{\\lineskiplimit} primitive}, \[248].
\:\\{line\_skip\_limit\_code}, \[247], 248.
\:\\{line\_stack}, \[304\*], 328\*, 329\*.
\:\\{line\_width}, \[830], 850, 851.
\:\\{link}, \[118], 120, 121, 122, 123, 124, 125, 126, 130, 133, 134\*, 135,
140, 143, 150, 164, 168, 172, 174\*, 175, 176\*, 182, 202, 204, 212, 214, 218,
223, 233, 292, 295, 306, 319, 323, 339, 357, 358, 366\*, 369, 371, 374, 389,
390, 391, 394, 396, 397, 400, 407\*, 464, 466, 467, 470, 478, 489, 495, 496,
497, 508, 582\*, 605, 607, 609, 611, 615, 620\*, 622, 630, 649, 651, 652, 654%
\*, 655, 666, 669, 679, 681, 689, 705, 711, 715, 718, 719, 720, 721, 727, 731,
732, 735, 737, 738, 739, 747, 748, 751, 752, 753, 754, 755, 756, 759, 760, 761,
766, 767, 770, 772, 778, 779, 783, 784, 786, 790, 791, 793, 794, 795, 796, 797,
798, 799, 801, 802, 803, 804, 805, 807, 808, 809, 812, 814, 816, 819, 821, 822,
829, 830, 837, 840, 841\*, 843, 844, 845, 854, 857, 858, 860, 861, 862, 863,
864, 865, 866, 867\*, 870, 873, 874, 875, 877, 879, 880, 881, 882, 883, 884,
885, 886, 887, 888, 890, 894, 896\*, 897, 898, 899\*, 903, 905, 907, 910, 911,
913, 914, 915, 916, 917, 918, 932, 938, 939, 968, 969, 970, 973, 979, 980, 981,
986, 988, 991, 994, 998, 999, 1000, 1001, 1005, 1008, 1009, 1014, 1017, 1018,
1019, 1020, 1021, 1022, 1023, 1026, 1035, 1039, 1041, 1043, 1064, 1065, 1076,
1081, 1086, 1091, 1100, 1101, 1105, 1110, 1119, 1120, 1121, 1122\*, 1123, 1125%
\*, 1146, 1155, 1168, 1181, 1184, 1185, 1186, 1187, 1191, 1194, 1196, 1199,
1204, 1206, 1226, 1279, 1288, 1297, 1311, 1312, 1335\*, 1339, 1341, 1349, 1368,
1370, 1371, 1375.
\:\\{list\_offset}, \[135], 649, 769, 1018.
\:\\{list\_ptr}, \[135], 136, 184, 202, 206, 619, 623, 629, 632, 658, 663\*,
664, 668, 673, 676, 709, 711, 715, 721, 739, 747, 751, 807, 977, 979, 1021,
1087, 1100, 1110, 1146.
\:\\{list\_state\_record}, \[212], 213.
\:\\{list\_tag}, \[544], 569, 570, 708, 740, 749.
\:\\{llink}, \[124], 126, 127, 129, 130, 131, 145, 149, 164, 169, 772, 819,
821, 1312.
\:\\{lo\_mem\_max}, \[116\*], 120, 125, 126, 164, 165, 167, 169, 170, 171, 172,
178, 639, 1311, 1312, 1323, 1334.
\:\\{lo\_mem\_stat\_max}, \[162], 164, 1312.
\:\\{load\_fmt\_file}, \[1303], 1337.
\:\\{loc}, \[36], 37\*, 87, 300, 302, 303, 307, 312, 314, 318, 319, 323, 325,
328\*, 330, 331, 343, 348, 350, 351, 352, 354, 356, 357, 358, 360, 362, 369,
390, 483, 524, 537, 538\*, 1026, 1027, 1337.
\:\\{loc\_field}, 36, \[300], 302.
\:\\{local\_base}, 220, \[224], 228, 230, 252.
\:\\{location}, \[605], 607, 612, 613, 614, 615.
\:\\{log\_file}, \[54], 56, 75, 534, 1333\*.
\:\\{log\_name}, \[532], 534, 1333\*.
\:\\{log\_only}, \[54], 57, 58, 62, 75, 98, 360, 534, 1328, 1370.
\:\9{long\_}{\.{\\long} primitive}, \[1208].
\:\\{long\_call}, \[210], 275, 366\*, 387, 389, 392, 399, 1295.
\:\\{long\_help\_seen}, \[1281], 1282, 1283.
\:\\{long\_outer\_call}, \[210], 275, 366\*, 387, 389, 1295.
\:\\{long\_state}, 339, \[387], 391, 392, 395, 396, 399.
\:\&{loop}, 15, \[16].
\:\.{Loose \\hbox...}, 660.
\:\.{Loose \\vbox...}, 674.
\:\\{loose\_fit}, \[817], 834, 852.
\:\\{looseness}, \[236], 848, 873, 875, 1070.
\:\9{looseness\_}{\.{\\looseness} primitive}, \[238].
\:\\{looseness\_code}, \[236], 237, 238, 1070.
\:\\{low\_mem\_max}, 120.
\:\9{lower\_}{\.{\\lower} primitive}, \[1071].
\:\9{lowercase\_}{\.{\\lowercase} primitive}, \[1286].
\:\\{lq}, \[592], 627, 636.
\:\\{lr}, \[592], 627, 636.
\:\\{lx}, \[619], 626, 627, 628, \[629], 635, 636, 637.
\:\|{m}, \[31\*], \[47], \[65], \[158], \[211], \[218], \[292], \[315], \[389],
\[413], \[440\*], \[482], \[498], \[577], \[649], \[668], \[706], \[716], %
\[717], \[1079], \[1105], \[1194], \[1338].
\:\\{mac\_param}, \[207], 291, 294, 298, 347, 474, 477, 479, 783, 784, 1045.
\:\\{macro}, \[307], 314, 319, 323, 324, 390.
\:\\{macro\_call}, 291, 366\*, 380, 382, 387, 388, \[389], 391.
\:\\{macro\_def}, \[473], 477.
\:\\{mag}, \[236], 240, 288, 457, 585, \[587], 588, 590, 617, 642\*.
\:\9{mag\_}{\.{\\mag} primitive}, \[238].
\:\\{mag\_code}, \[236], 237, 238, 288.
\:\\{mag\_set}, \[286], 287, 288.
\:\\{magic\_offset}, \[764], 765, 766.
\:\\{main\_control}, 1029, \[1030], 1041, 1052, 1054, 1055, 1056, 1057, 1126,
1134, 1208, 1290, 1332, 1337, 1344, 1347.
\:\\{main\_loop}, \[1030].
\:\\{main\_loop\_1}, \[1030], 1033, 1036.
\:\\{main\_loop\_2}, \[1030], 1033, 1038.
\:\\{main\_loop\_3}, \[1030], 1033, 1040.
\:\\{major\_tail}, \[912], 914, 916.
\:\\{make\_accent}, 1122\*, \[1123].
\:\\{make\_box}, \[208\*], 1071, 1072, 1073, 1079, 1084.
\:\\{make\_fraction}, 733, 734, \[743].
\:\\{make\_left\_right}, 761, \[762].
\:\\{make\_mark}, 1097, \[1101].
\:\\{make\_math\_accent}, 733, \[738].
\:\\{make\_name\_string}, \[525\*].
\:\\{make\_op}, 733, \[749].
\:\\{make\_ord}, 733, \[752].
\:\\{make\_over}, 733, \[734].
\:\\{make\_radical}, 733, 734, \[737].
\:\\{make\_scripts}, 754, \[756].
\:\\{make\_string}, \[43], 48, 52, 84\*, 260, 517\*, 525\*, 642\*, 939, 1257,
1279, 1328, 1333\*.
\:\\{make\_under}, 733, \[735].
\:\\{make\_vcenter}, 733, \[736].
\:\\{mark}, \[208\*], 265\*, 266\*, 1097.
\:\9{mark\_}{\.{\\mark} primitive}, \[265\*].
\:\\{mark\_node}, \[141], 148, 175, 183\*, 202, 206, 647, 651, 730, 761, 866,
899\*, 968, 973, 979, 1000, 1014, 1101.
\:\\{mark\_ptr}, \[141], 142, 196, 202, 206, 979, 1016, 1101.
\:\\{mark\_text}, \[307], 314, 323, 386.
\:{mastication}, 341\*.
\:\\{match}, \[207], 289, 291, 292, 294, 391, 392.
\:\\{match\_chr}, \[292], 294, \[389], 391, 400.
\:\\{match\_token}, \[289], 391, 392, 393, 394, 476.
\:\\{matching}, \[305], 306, 339, 391.
\:\.{Math formula deleted...}, 1195.
\:\\{math\_ac}, 1164, \[1165].
\:\\{math\_accent}, \[208\*], 265\*, 266\*, 1046\*, 1164.
\:\9{math\_accent\_}{\.{\\mathaccent} primitive}, \[265\*].
\:\9{math\_bin\_}{\.{\\mathbin} primitive}, \[1156].
\:\\{math\_char}, \[681], 692, 720, 722, 724, 738, 741, 749, 752, 753, 754,
1151, 1155, 1165.
\:\9{math\_char\_}{\.{\\mathchar} primitive}, \[265\*].
\:\9{math\_char\_def\_}{\.{\\mathchardef} primitive}, \[1222].
\:\\{math\_char\_def\_code}, \[1222], 1223, 1224.
\:\\{math\_char\_num}, \[208\*], 265\*, 266\*, 1046\*, 1151, 1154.
\:\\{math\_choice}, \[208\*], 265\*, 266\*, 1046\*, 1171.
\:\9{math\_choice\_}{\.{\\mathchoice} primitive}, \[265\*].
\:\\{math\_choice\_group}, \[269], 1172, 1173, 1174.
\:\9{math\_close\_}{\.{\\mathclose} primitive}, \[1156].
\:\\{math\_code}, \[230], 232\*, 236, 414, 1151, 1154.
\:\9{math\_code\_}{\.{\\mathcode} primitive}, \[1230].
\:\\{math\_code\_base}, \[230], 235, 414, 1230, 1231, 1232, 1233.
\:\\{math\_comp}, \[208\*], 1046\*, 1156, 1157, 1158.
\:\\{math\_font\_base}, \[230], 232\*, 234, 1230, 1231.
\:\\{math\_fraction}, 1180, \[1181].
\:\\{math\_given}, \[208\*], 413, 1046\*, 1151, 1154, 1222, 1223, 1224.
\:\\{math\_glue}, \[716], 732, 766.
\:\\{math\_group}, \[269], 1136, 1150, 1153, 1186.
\:\9{math\_inner\_}{\.{\\mathinner} primitive}, \[1156].
\:\\{math\_kern}, \[717], 730.
\:\\{math\_left\_group}, \[269], 1065, 1068\*, 1069, 1150, 1191.
\:\\{math\_left\_right}, 1190, \[1191].
\:\\{math\_limit\_switch}, 1158, \[1159].
\:\\{math\_node}, \[147], 148, 175, 183\*, 202, 206, 622, 651, 817, 837, 866,
879, 881, 1147\*.
\:\9{math\_op\_}{\.{\\mathop} primitive}, \[1156].
\:\9{math\_open\_}{\.{\\mathopen} primitive}, \[1156].
\:\9{math\_ord\_}{\.{\\mathord} primitive}, \[1156].
\:\9{math\_punct\_}{\.{\\mathpunct} primitive}, \[1156].
\:\\{math\_quad}, \[700], 703, 1199.
\:\\{math\_radical}, 1162, \[1163].
\:\9{math\_rel\_}{\.{\\mathrel} primitive}, \[1156].
\:\\{math\_shift}, \[207], 289, 294, 298, 347, 1090\*, 1137, 1138, 1193, 1197,
1206.
\:\\{math\_shift\_group}, \[269], 1065, 1068\*, 1069, 1139, 1142, 1145, 1192,
1193, 1194, 1200.
\:\\{math\_shift\_token}, \[289], 1047, 1065.
\:\\{math\_spacing}, \[764], 765.
\:\\{math\_style}, \[208\*], 1046\*, 1169, 1170, 1171.
\:\\{math\_surround}, \[247], 1196.
\:\9{math\_surround\_}{\.{\\mathsurround} primitive}, \[248].
\:\\{math\_surround\_code}, \[247], 248.
\:\\{math\_text\_char}, \[681], 752, 754, 755.
\:\\{math\_type}, \[681], 683, 687, 692, 698, 720, 722, 723, 734, 735, 737,
738, 741, 742, 749, 751, 752, 753, 754, 755, 756, 1076, 1093, 1151, 1155, 1165,
1168, 1176, 1181, 1185, 1186, 1191.
\:\\{math\_x\_height}, \[700], 737, 757, 758, 759.
\:\\{mathex}, \[701].
\:\\{mathsy}, \[700].
\:\\{mathsy\_end}, \[700].
\:\\{max\_buf\_stack}, \[30\*], 31\*, 331, 374, 1334.
\:\\{max\_char\_code}, \[207], 303, 344, 1233.
\:\\{max\_command}, \[209\*], 210, 211, 219, 358, 366\*, 368, 380, 381, 478,
782.
\:\\{max\_d}, \[726], 727, 730, 760, 761, \[762].
\:\\{max\_dead\_cycles}, \[236], 240, 1012.
\:\9{max\_dead\_cycles\_}{\.{\\maxdeadcycles} primitive}, \[238].
\:\\{max\_dead\_cycles\_code}, \[236], 237, 238.
\:\\{max\_depth}, \[247], 980, 987.
\:\9{max\_depth\_}{\.{\\maxdepth} primitive}, \[248].
\:\\{max\_depth\_code}, \[247], 248.
\:\\{max\_dimen}, \[421], 460, 641, 668, 1010, 1017, 1145, 1146, 1148.
\:\\{max\_group\_code}, \[269].
\:\\{max\_h}, \[592], 593, 641, 642\*, \[726], 727, 730, 760, 761, \[762].
\:\\{max\_halfword}, 11\*, 14, \[110\*], 111, 113, 124, 125, 126, 131, 132,
289, 290, 424, 820, 848, 850, 982, 991, 996, 1017, 1106, 1249, 1323, 1325.
\:\\{max\_in\_open}, \[11\*], 14, 304\*, 328\*.
\:\\{max\_in\_stack}, \[301], 321, 331, 1334.
\:\\{max\_internal}, \[209\*], 413, 440\*, 448\*, 455, 461.
\:\\{max\_nest\_stack}, \[213], 215, 216, 1334.
\:\\{max\_non\_prefixed\_command}, \[208\*], 1211, 1270.
\:\\{max\_param\_stack}, \[308], 331, 390, 1334.
\:\\{max\_print\_line}, \[11\*], 14, 54, 58, 61, 72, 176\*, 537, 638, 1280.
\:\\{max\_push}, \[592], 593, 619, 629, 642\*.
\:\\{max\_quarterword}, 11\*, \[110\*], 111, 113, 274, 797, 798, 943, 944,
1120, 1325.
\:\\{max\_save\_stack}, \[271], 272, 273, 1334.
\:\\{max\_selector}, \[54], 246, 311, 465, 470, 534, 638, 1257, 1279, 1368,
1370.
\:\\{max\_strings}, \[11\*], 38, 43, 84\*, 111, 517\*, 525\*, 642\*, 1310, 1334.
\:\\{max\_v}, \[592], 593, 641, 642\*.
\:\9{meaning\_}{\.{\\meaning} primitive}, \[468].
\:\\{meaning\_code}, \[468], 469, 471, 472.
\:\\{med\_mu\_skip}, \[224].
\:\9{med\_mu\_skip\_}{\.{\\medmuskip} primitive}, \[226].
\:\\{med\_mu\_skip\_code}, \[224], 225, 226, 766.
\:\\{mem}, 11\*, 12\*, 115, 116\*, 118, 124, 126, 131, 133, 134\*, 135, 140,
141, 150, 151, 157, 159, 162, 163, 164, 165, 167, 172, 182, 186, 203, 205, 206,
221, 224, 275, 291, 387, 420, 489, 605, 652, 680, 681, 683, 686, 687, 720, 725,
742, 753, 769, 770, 772, 797, 816, 818, 819, 822, 823, 832, 843, 844, 847, 848,
850, 860, 861, 889, 925, 1149, 1151, 1160, 1163, 1165, 1181, 1186, 1247, 1248,
1311, 1312, 1339, \[1379\*].
\:\\{mem\_bot}, 11\*, \[12\*], 14, 111, 116\*, 125, 126, 162, 164, 1307, 1308,
1311, 1312.
\:\\{mem\_end}, 116\*, \[118], 120, 164, 165, 167, 168, 171, 172, 174\*, 176\*,
182, 293, 1311, 1312, 1334.
\:\\{mem\_max}, \[11\*], 12\*, 14, 110\*, 111, 116\*, 120, 124, 125, 165, 166,
1379\*.
\:\\{mem\_min}, \[11\*], 12\*, 111, 116\*, 120, 125, 165, 166, 167, 169, 170,
171, 172, 174\*, 178, 182, 1249, 1312, 1334, 1379\*.
\:\\{mem\_top}, 11\*, \[12\*], 14, 111, 116\*, 162, 164, 1249, 1307, 1308, 1312.
\:\.{Memory usage...}, 639.
\:\\{memory\_word}, 110\*, \[113], 114, 182, 221, 253, 268, 271, 275, 548, 549,
1305, 1379\*.
\:\\{message}, \[208\*], 1276, 1277, 1278.
\:\9{message\_}{\.{\\message} primitive}, \[1277].
\:\9{METAFONT}{\MF}, 589.
\:\\{mid}, \[546].
\:\\{mid\_line}, 87, \[303], 328\*, 344, 347, 352, 353, 354.
\:\\{min\_halfword}, 11\*, \[110\*], 111, 113, 115, 230, 1323, 1325.
\:\\{min\_internal}, \[208\*], 413, 440\*, 448\*, 455, 461.
\:\\{min\_quarterword}, 12\*, \[110\*], 111, 112\*, 113, 134\*, 136, 140, 185,
221, 274, 545, 550, 554, 556, 566, 576, 649, 668, 685, 697, 707, 713, 714, 796,
801, 803, 808, 920, 923, 924, 943, 944, 949, 952, 960, 963, 964, 965, 966, 994,
1012, 1324, 1325.
\:\\{minimal\_demerits}, \[833], 834, 836, 845, 855.
\:\\{minimum\_demerits}, \[833], 834, 835, 836, 854, 855.
\:\\{minor\_tail}, \[912], 915, 916.
\:\.{minus}, 462.
\:\.{Misplaced \&}, 1128.
\:\.{Misplaced \\cr}, 1128.
\:\.{Misplaced \\noalign}, 1129.
\:\.{Misplaced \\omit}, 1129.
\:\.{Misplaced \\span}, 1128.
\:\.{Missing = inserted}, 503.
\:\.{Missing \# inserted...}, 783.
\:\.{Missing \$ inserted}, 1047, 1065.
\:\.{Missing \\cr inserted}, 1132.
\:\.{Missing \\endcsname...}, 373.
\:\.{Missing \\endgroup inserted}, 1065.
\:\.{Missing \\right\hbox{.} inserted}, 1065.
\:\.{Missing \{ inserted}, 403, 475, 1127.
\:\.{Missing \} inserted}, 1065, 1127.
\:\.{Missing `to' inserted}, 1082.
\:\.{Missing `to'...}, 1225.
\:\.{Missing {\$\$} inserted}, 1207.
\:\.{Missing character}, 581.
\:\.{Missing control...}, 1215.
\:\.{Missing delimiter...}, 1161.
\:\.{Missing font identifier}, 577.
\:\.{Missing number...}, 415, 446.
\:\\{mkern}, \[208\*], 1046\*, 1057, 1058, 1059.
\:\9{mkern\_}{\.{\\mkern} primitive}, \[1058].
\:\\{ml\_field}, \[212], 213, 218.
\:\\{mlist}, \[726], 760.
\:\\{mlist\_penalties}, \[719], 720, 726, 754, 1194, 1196, 1199.
\:\\{mlist\_to\_hlist}, 693, 719, 720, 725, \[726], 734, 754, 760, 1194, 1196,
1199.
\:\.{mm}, 458.
\:\\{mmode}, \[211], 212, 213, 218, 501, 718, 775, 776, 800, 812, 1030, 1045,
1046\*, 1048, 1056, 1057, 1073, 1078, 1080, 1092, 1097, 1109, 1110, 1112, 1116,
1120, 1130, 1136, 1140, 1145, 1150, 1154, 1158, 1162, 1164, 1167, 1171, 1175,
1180, 1190, 1193, 1194.
\:\\{mode}, 211, 212, \[213], 215, 216, 299, 418, 424, 501, 718, 775, 776, 785,
786, 787, 796, 799, 804, 807, 808, 809, 812, 1025, 1029, 1030, 1039, 1049,
1051, 1056, 1076, 1078, 1080, 1083, 1086, 1091, 1093, 1094, 1095, 1096, 1099,
1103, 1105, 1110, 1117, 1119, 1120, 1136, 1138, 1145, 1167, 1194, 1196, 1200,
1243, 1370, 1371.
\:\\{mode\_field}, \[212], 213, 218, 422, 800, 1244.
\:\\{mode\_line}, 212, \[213], 215, 216, 304\*, 804, 815, 1025.
\:\\{month}, \[236], 241\*, 536, 617, 1328.
\:\9{month\_}{\.{\\month} primitive}, \[238].
\:\\{month\_code}, \[236], 237, 238.
\:\\{months}, \[534], 536.
\:\\{more\_name}, 512, \[516\*], 526, 531.
\:\9{move\_left\_}{\.{\\moveleft} primitive}, \[1071].
\:\\{move\_past}, \[619], 622, 625, 629, 631, 634.
\:\9{move\_right\_}{\.{\\moveright} primitive}, \[1071].
\:\\{movement}, \[607], 609, 616.
\:\\{movement\_node\_size}, \[605], 607, 615.
\:\\{mskip}, \[208\*], 1046\*, 1057, 1058, 1059, 1078.
\:\9{mskip\_}{\.{\\mskip} primitive}, \[1058].
\:\\{mskip\_code}, \[1058], 1060.
\:\\{mstate}, \[607], 611, 612.
\:\&{mtype}, \[4].
\:\\{mu}, 447, \[448\*], 449, 453, 455, \[461], 462.
\:\.{mu}, 456.
\:\\{mu\_error}, \[408], 429, 449, 455, 461.
\:\\{mu\_glue}, \[149], 155, 191, 424, 717, 732, 1058, 1060, 1061.
\:\\{mu\_mult}, \[716], 717.
\:\\{mu\_skip}, \[224], 427.
\:\9{mu\_skip\_}{\.{\\muskip} primitive}, \[411].
\:\\{mu\_skip\_base}, \[224], 227, 229, 1224, 1237.
\:\9{mu\_skip\_def\_}{\.{\\muskipdef} primitive}, \[1222].
\:\\{mu\_skip\_def\_code}, \[1222], 1223, 1224.
\:\\{mu\_val}, \[410], 411, 413, 424, 427, 429, 430, 449, 451, 455, 461, 465,
1060, 1228, 1236, 1237.
\:\\{multiply}, \[209\*], 265\*, 266\*, 1210, 1235, 1236, 1240.
\:\9{multiply\_}{\.{\\multiply} primitive}, \[265\*].
\:\.{Must increase the x}, 1303.
\:\|{n}, \[31\*], \[47], \[65], \[66], \[67], \[69], \[91], \[94], \[105], %
\[106], \[107], \[152], \[154], \[174\*], \[182], \[225], \[237], \[247], %
\[252], \[292], \[315], \[389], \[482], \[498], \[518\*], \[519\*], \[523\*], %
\[578], \[706], \[716], \[717], \[791], \[800], \[906], \[934], \[944], \[977],
\[992], \[993], \[994], \[1012], \[1079], \[1119], \[1138], \[1211], \[1275], %
\[1338].
\:\\{name}, 300, \[302], 303, 304\*, 307, 311, 313\*, 314, 323, 328\*, 329\*,
331, 337, 360, 390, 483, 537.
\:\\{name\_field}, 84\*, \[300], 302.
\:\\{name\_in\_progress}, 378, 526, \[527], 528, 1258.
\:\\{name\_length}, \[26], 51, 519\*, 523\*, 525\*.
\:\\{name\_of\_file}, \[26], 27\*, 51, 519\*, 523\*, 525\*, 530\*.
\:\\{natural}, \[644], 705, 715, 720, 727, 735, 737, 738, 748, 754, 756, 759,
796, 799, 977, 1021, 1100, 1125\*, 1194, 1199, 1204.
\:\\{nd}, 540, 541, \[560], 565, 566, 569.
\:\\{ne}, 540, 541, \[560], 565, 566, 569.
\:\\{negate}, \[16], 65, 103, 105, 106, 107, 430, 431, 440\*, 448\*, 461, 775.
\:\\{negative}, \[106], \[413], 430, \[440\*], 441, \[448\*], \[461].
\:\\{nest}, 212, \[213], 216, 217, 218, 219, 413, 422, 775, 800, 995, 1244.
\:\\{nest\_ptr}, \[213], 215, 216, 217, 218, 422, 775, 800, 995, 1017, 1023,
1091, 1100, 1145, 1200, 1244.
\:\\{nest\_size}, \[11\*], 213, 216, 218, 413, 1244, 1334.
\:\\{new\_character}, \[582\*], 755, 915, 918, 1117, 1123, 1124\*.
\:\\{new\_choice}, \[689], 1172.
\:\\{new\_delta\_from\_break\_width}, \[844].
\:\\{new\_delta\_to\_break\_width}, \[843].
\:\\{new\_disc}, \[145], 918, 1039, 1117.
\:\\{new\_font}, 1256, \[1257].
\:\\{new\_glue}, \[153], 154, 715, 766, 786, 793, 795, 809, 1041, 1043, 1054,
1060, 1171.
\:\\{new\_graf}, 1090\*, \[1091].
\:\\{new\_hlist}, \[725], 727, 743, 748, 749, 750, 754, 756, 762, 767.
\:\\{new\_hyph\_exceptions}, \[934], 1252.
\:\\{new\_interaction}, 1264, \[1265].
\:\\{new\_kern}, \[156], 705, 715, 735, 738, 739, 747, 751, 753, 755, 759, 911,
1038, 1061, 1112, 1113, 1125\*, 1204.
\:\\{new\_ligature}, \[144], 910, 1039.
\:\\{new\_line}, \[303], 331, 343, 344, 345, 347, 483, 537.
\:\\{new\_line\_char}, \[236], 244.
\:\9{new\_line\_char\_}{\.{\\newlinechar} primitive}, \[238].
\:\\{new\_line\_char\_code}, \[236], 237, 238.
\:\\{new\_math}, \[147], 1196.
\:\\{new\_noad}, \[686], 720, 742, 1076, 1093, 1150, 1155, 1158, 1168, 1177,
1191.
\:\\{new\_null\_box}, \[136], 706, 709, 713, 720, 747, 750, 779, 793, 809,
1018, 1054, 1091, 1093.
\:\\{new\_param\_glue}, \[152], 154, 679, 778, 816, 886, 887, 1041, 1043, 1091,
1203, 1205, 1206.
\:\\{new\_patterns}, \[960], 1252.
\:\\{new\_penalty}, \[158], 767, 816, 890, 1054, 1103, 1203, 1205, 1206.
\:\\{new\_rule}, \[139], 463, 666, 704.
\:\\{new\_save\_level}, \[274], 774, 785, 791, 1025, 1063\*, 1083, 1099, 1117,
1119, 1136, 1167.
\:\\{new\_skip\_param}, \[154], 679, 969, 1001.
\:\\{new\_spec}, \[151], 154, 430, 462, 826, 976, 1004, 1042, 1043, 1239, 1240.
\:\\{new\_string}, \[54], 57, 58, 84\*, 465, 470, 617, 642\*, 1257, 1279, 1328,
1368.
\:\\{new\_style}, \[688], 1171.
\:\\{new\_trie\_op}, 943, \[944], 965.
\:\\{new\_whatsit}, \[1349], 1350, 1354.
\:\\{new\_write\_whatsit}, \[1350], 1351, 1352, 1353.
\:\\{new\_xchar}, \[582\*], 1122\*, 1124\*.
\:\\{next}, \[256], 257, 259, 260.
\:\\{next\_break}, \[877], 878, 883.
\:\\{next\_char}, \[545], 741, 753, 908, 1037.
\:\\{next\_p}, \[619], 622, 626, 629, 630, 631, 633, 635.
\:\\{nh}, 540, 541, \[560], 565, 566, 569.
\:\\{ni}, 540, 541, \[560], 565, 566, 569.
\:\&{nil}, 16.
\:\\{nk}, 540, 541, \[560], 565, 566, 573.
\:\\{nl}, 540, 541, \[560], 565, 566, 569, 573.
\:\.{No pages of output}, 642\*.
\:\\{no\_align}, \[208\*], 265\*, 266\*, 785, 1126.
\:\9{no\_align\_}{\.{\\noalign} primitive}, \[265\*].
\:\\{no\_align\_error}, 1126, \[1129].
\:\\{no\_align\_group}, \[269], 768, 785, 1133.
\:\\{no\_break\_yet}, \[829], 836, 837.
\:\\{no\_expand}, \[210], 265\*, 266\*, 358, 366\*, 367.
\:\9{no\_expand\_}{\.{\\noexpand} primitive}, \[265\*].
\:\\{no\_expand\_flag}, \[358], 506.
\:\9{no\_indent\_}{\.{\\noindent} primitive}, \[1088].
\:\\{no\_limits}, \[682], 1156, 1157.
\:\9{no\_limits\_}{\.{\\nolimits} primitive}, \[1156].
\:\\{no\_new\_control\_sequence}, \[256], 257, 259, 264, 365, 374, 1336.
\:\\{no\_print}, \[54], 57, 58, 75, 98.
\:\\{no\_shrink\_error\_yet}, \[825], 826, 827.
\:\\{no\_tag}, \[544], 569.
\:\\{noad\_size}, \[681], 686, 698, 753, 761, 1186, 1187.
\:\\{node\_list\_display}, \[180], 184, 188, 190, 195, 197.
\:\\{node\_r\_stays\_active}, \[830], 851, 854.
\:\\{node\_size}, \[124], 126, 127, 128, 130, 164, 169, 1311, 1312.
\:\\{nom}, \[560], 561, 563, 576.
\:\\{non\_discardable}, \[148], 879.
\:\\{non\_math}, \[1046\*], 1063\*, 1144.
\:\\{non\_script}, \[208\*], 265\*, 266\*, 1046\*, 1171.
\:\9{non\_script\_}{\.{\\nonscript} primitive}, \[265\*].
\:\\{none\_seen}, \[611], 612.
\:\.{NONEXISTENT}, 262.
\:\.{Nonletter}, 962.
\:\\{nonnegative\_integer}, 69, \[101], 107.
\:\\{nonstop\_mode}, \[73], 86, 360, 363\*, 484, 1262, 1263.
\:\9{nonstop\_mode\_}{\.{\\nonstopmode} primitive}, \[1262].
\:\\{nop}, 583, 585, \[586], 588, 590.
\:\\{normal}, \[135], 136, 149, 150, 153, 155, 156, 164, 177, 186, 189, 191,
305, 331, 336\*, 369, 448\*, 471, 473, 480, 482, 485\*, 489, 490, 507, 619,
625, 629, 634, 650, 657, 658, 659, 660, 664, 665, 666, 667, 672, 673, 674, 676,
677, 678, 682, 686, 696, 716, 717, 732, 749, 777, 801, 810, 811, 825, 826, 896%
\*, 897, 899\*, 976, 988, 1004, 1009, 1156, 1163, 1165, 1181, 1201, 1219, 1220,
1221, 1239.
\:\\{normal\_paragraph}, 774, 785, 787, 1025, \[1070], 1083, 1094, 1096, 1099,
1167.
\:\\{normalize\_selector}, 78, \[92], 93, 94, 95.
\:\.{Not a letter}, 937.
\:\\{not\_equal}, 23\*.
\:\\{not\_found}, \[15], 45, 46, 448\*, 455, 560, 570, 607, 611, 612, 895, 930,
931, 934, 941, 953, 955, 970, 972, 973, 1138, 1146, 1364.
\:\.{notexpanded:}, 258.
\:\\{np}, 540, 541, \[560], 565, 566, 575, 576.
\:\\{nucleus}, \[681], 682, 683, 686, 687, 690, 696, 698, 720, 725, 734, 735,
736, 737, 738, 741, 742, 749, 750, 752, 753, 754, 755, 1076, 1093, 1150, 1151,
1155, 1158, 1163, 1165, 1168, 1186, 1191.
\:\\{null}, \[115], 116\*, 118, 120, 122, 123, 125, 126, 135, 136, 145, 149,
150, 151, 152, 153, 154, 164, 168, 169, 175, 176\*, 182, 200, 201, 202, 204,
210, 212, 218, 219, 222, 223, 232\*, 233, 275, 292, 295, 306, 307, 312, 314,
325, 331, 357, 358, 371, 374, 382, 383, 386, 390, 391, 392, 397, 400, 407\*,
410, 420, 423, 464, 466, 473, 478, 482, 489, 490, 497, 505, 508, 549, 552, 576,
578, 582\*, 606, 611, 615, 619, 623, 629, 632, 648, 649, 651, 655, 658, 664,
666, 668, 673, 676, 681, 685, 689, 692, 715, 718, 719, 720, 721, 726, 731, 732,
752, 754, 755, 756, 760, 761, 766, 767, 771, 774, 776, 777, 783, 784, 790, 791,
792, 794, 796, 797, 799, 801, 804, 805, 807, 812, 821, 829, 837, 840, 846, 847,
848, 850, 856, 857, 858, 859, 863, 864, 865, 867\*, 870, 872, 877, 878, 879,
881, 882, 883, 884, 885, 887, 888, 889, 894, 898, 903, 905, 913, 914, 915, 916,
917, 918, 928, 932, 935, 939, 968, 969, 970, 972, 973, 977, 978, 979, 981, 991,
992, 993, 994, 998, 999, 1000, 1009, 1010, 1011, 1012, 1014, 1015, 1016, 1017,
1018, 1020, 1021, 1022, 1023, 1026, 1027, 1028, 1030, 1042, 1043, 1070, 1074,
1075, 1076, 1079, 1080, 1081, 1083, 1087, 1091, 1105, 1110, 1121, 1122\*, 1123,
1124\*, 1136, 1139, 1145, 1146, 1149, 1167, 1174, 1176, 1181, 1184, 1185, 1186,
1194, 1196, 1199, 1202, 1205, 1206, 1226, 1227, 1247, 1248, 1283, 1288, 1296,
1311, 1312, 1335\*, 1339, 1353, 1354, 1368, 1369, 1370, 1375.
\:{null delimiter}, 240, 1065.
\:\\{null\_character}, \[555], 556, 722, 723.
\:\\{null\_code}, \[22], 232\*.
\:\\{null\_cs}, \[222], 262, 263, 354, 374, 1257.
\:\\{null\_delimiter}, \[684], 685, 1181.
\:\\{null\_delimiter\_space}, \[247], 706.
\:\9{null\_delimiter\_space\_}{\.{\\nulldelimiterspace} primitive}, \[248].
\:\\{null\_delimiter\_space\_code}, \[247], 248.
\:\\{null\_flag}, \[138], 139, 463, 653, 779, 793, 801.
\:\\{null\_font}, \[232\*], 552, 553, 560, 577, 617, 663\*, 706, 707, 722, 864,
1257, 1320, 1321, 1339.
\:\9{null\_font\_}{\.{\\nullfont} primitive}, \[553].
\:\\{null\_list}, \[162], 380, 780.
\:\\{num}, \[450], 458, 585, \[587], 590.
\:\\{num\_style}, \[702], 744.
\:\.{Number too big}, 445.
\:\9{number\_}{\.{\\number} primitive}, \[468].
\:\\{number\_code}, \[468], 469, 470, 471, 472.
\:\\{numerator}, \[683], 690, 697, 698, 744, 1181, 1185.
\:\\{num1}, \[700], 744.
\:\\{num2}, \[700], 744.
\:\\{num3}, \[700], 744.
\:\\{nw}, 540, 541, \[560], 565, 566, 569.
\:\\{nx\_plus\_y}, \[105], 455, 716, 1240.
\:\|{o}, \[264], \[597\*], \[607], \[649], \[668], \[791], \[800].
\:\\{octal\_token}, \[438], 444.
\:\\{odd}, 62, 100, 504, 758, 902, 908, 913, 1211, 1218.
\:\\{off\_save}, 1063\*, \[1064], 1094, 1095, 1131, 1192, 1193.
\:\.{OK}, 1298.
\:\\{OK\_so\_far}, \[440\*], 445.
\:\\{OK\_to\_interrupt}, 88, \[96], 97, 98, 327, 1031.
\:\\{old\_l}, \[829], 835, 850.
\:\\{old\_mode}, \[1370], 1371.
\:\\{old\_rover}, \[131].
\:\\{old\_setting}, 245, \[246], \[311], 312, \[465], \[470], \[534], 617, %
\[638], \[1257], \[1279], \[1368], \[1370].
\:\\{omit}, \[208\*], 265\*, 266\*, 788, 789, 1126.
\:\9{omit\_}{\.{\\omit} primitive}, \[265\*].
\:\\{omit\_error}, 1126, \[1129].
\:\\{omit\_template}, \[162], 789, 790.
\:\.{Only one \# is allowed...}, 784.
\:\\{op\_bit}, \[545], 741, 753, 908, 1037.
\:\\{op\_noad}, \[682], 690, 696, 698, 726, 728, 733, 749, 761, 1156, 1157,
1159.
\:\\{open\_area}, \[1341], 1351, 1356, 1374.
\:\\{open\_ext}, \[1341], 1351, 1356, 1374.
\:\\{open\_fmt\_file}, \[524], 1337.
\:\9{open\_in\_}{\.{\\openin} primitive}, \[1272].
\:\\{open\_log\_file}, 78, 92, 360, 471, 532, \[534], 535, 537, 1257, 1335\*.
\:\\{open\_name}, \[1341], 1351, 1356, 1374.
\:\\{open\_noad}, \[682], 690, 696, 698, 728, 733, 761, 762, 1156, 1157.
\:\\{open\_node}, \[1341], 1344, 1346, 1348, 1356, 1357, 1358, 1373.
\:\\{open\_node\_size}, \[1341], 1351, 1357, 1358.
\:\\{open\_or\_close\_in}, 1274, \[1275].
\:\9{open\_out\_}{\.{\\openout} primitive}, \[1344].
\:\9{or\_}{\.{\\or} primitive}, \[491].
\:\\{or\_code}, \[489], 491, 492, 500, 509.
\:\\{ord}, 20, 37\*.
\:\\{ord\_noad}, 681, \[682], 686, 687, 690, 696, 698, 728, 729, 733, 752, 753,
761, 764, 765, 1075, 1155, 1156, 1157, 1186.
\:\\{order}, \[177].
\:{oriental characters}, 134\*, 585.
\:\\{other\_A\_token}, \[445].
\:\\{other\_char}, \[207], 232\*, 289, 291, 294, 298, 347, 445, 464, 526, 935,
961, 1030, 1036, 1090\*, 1124\*, 1151, 1154, 1160.
\:\\{other\_token}, \[289], 405, 438, 441, 445, 464, 503, 1065, 1221.
\:\&{othercases}, \[10].
\:\\{others}, 10.
\:\.{Ouch...clobbered}, 1332.
\:\\{out\_param}, \[207], 289, 291, 294, 357.
\:\\{out\_param\_token}, \[289], 479.
\:\\{out\_what}, 1365, 1366, \[1373], 1375.
\:\9{outer\_}{\.{\\outer} primitive}, \[1208].
\:\\{outer\_call}, \[210], 275, 339, 351, 353, 354, 357, 366\*, 387, 391, 396,
780, 1152, 1295, 1369.
\:\\{outer\_doing\_leaders}, \[619], 628, \[629], 637.
\:\\{output}, \[4].
\:\.{Output loop...}, 1024.
\:\.{Output routine didn't use...}, 1028.
\:\.{Output written on x}, 642\*.
\:\9{output\_}{\.{\\output} primitive}, \[230].
\:\\{output\_active}, 663\*, 675\*, 986, \[989], 990, 994, 1005, 1025, 1026.
\:\\{output\_file\_name}, \[532], 533, 642\*.
\:\\{output\_group}, \[269], 1025, 1100.
\:\\{output\_penalty}, \[236].
\:\9{output\_penalty\_}{\.{\\outputpenalty} primitive}, \[238].
\:\\{output\_penalty\_code}, \[236], 237, 238, 1013.
\:\\{output\_routine}, \[230], 1012, 1025.
\:\\{output\_routine\_loc}, \[230], 231, 232\*, 307, 323, 1226.
\:\\{output\_text}, \[307], 314, 323, 1025.
\:\9{over\_}{\.{\\over} primitive}, \[1178].
\:\\{over\_code}, \[1178], 1179, 1182.
\:\\{over\_noad}, \[687], 690, 696, 698, 733, 761, 1156.
\:\9{over\_with\_delims\_}{\.{\\overwithdelims} primitive}, \[1178].
\:\\{overbar}, \[705], 734, 737.
\:\\{overflow}, 31\*, 42, 43, \[94], 120, 125, 216, 260, 273, 274, 321, 328\*,
374, 390, 517\*, 580, 642\*, 940, 954, 964, 1333\*.
\:{Overflow in arithmetic}, 9\*, 104.
\:\.{Overfull \\hbox...}, 666.
\:\.{Overfull \\vbox...}, 677.
\:{overfull boxes}, 854.
\:\\{overfull\_rule}, \[247], 666, 800, 804.
\:\9{overfull\_rule\_}{\.{\\overfullrule} primitive}, \[248].
\:\\{overfull\_rule\_code}, \[247], 248.
\:\9{overline\_}{\.{\\overline} primitive}, \[1156].
\:\|{p}, \[120], \[123], \[125], \[130], \[131], \[136], \[139], \[144], %
\[145], \[147], \[151], \[152], \[153], \[154], \[156], \[158], \[167], \[172],
\[174\*], \[176\*], \[178], \[182], \[198], \[200], \[201], \[202], \[204], %
\[218], \[259], \[262], \[263], \[276], \[277], \[278], \[279], \[281], \[284],
\[292], \[295], \[306], \[315], \[323], \[325], \[336\*], \[366\*], \[389], %
\[407\*], \[413], \[464], \[465], \[473], \[482], \[497], \[498], \[582\*], %
\[607], \[615], \[619], \[629], \[638], \[649], \[668], \[679], \[686], \[688],
\[689], \[691], \[692], \[704], \[705], \[709], \[711], \[715], \[716], \[717],
\[720], \[726], \[735], \[738], \[743], \[749], \[752], \[756], \[772], \[774],
\[787], \[791], \[799], \[800], \[826], \[906], \[934], \[947], \[948], \[949],
\[951], \[953], \[957], \[959], \[960], \[968], \[970], \[993], \[994], %
\[1012], \[1032], \[1043], \[1064], \[1068\*], \[1075], \[1079], \[1086], %
\[1093], \[1101], \[1105], \[1110], \[1113], \[1119], \[1123], \[1138], %
\[1151], \[1155], \[1160], \[1174], \[1176], \[1184], \[1191], \[1194], %
\[1211], \[1236], \[1244], \[1288], \[1293], \[1302], \[1303], \[1348], %
\[1349], \[1355], \[1368], \[1370], \[1373].
\:\\{pack\_begin\_line}, \[661], 662, 663\*, 675\*, 804, 815.
\:\\{pack\_buffered\_name}, \[523\*], 524.
\:\\{pack\_cur\_name}, \[529], 530\*, 537, 1275, 1374.
\:\\{pack\_file\_name}, \[519\*], 529, 537, 563.
\:\\{pack\_job\_name}, \[529], 532, 534, 1328.
\:\\{package}, 1085, \[1086].
\:\\{packed\_bytes}, \[594\*], 595\*, 597\*.
\:\\{page}, 31\*, 84\*, \[304\*], 313\*, 328\*, 329\*, 494\*, 538\*, 663\*, 675%
\*, 1378\*.
\:\\{page\_contents}, 421, \[980], 986, 987, 991, 1000, 1001, 1008.
\:\\{page\_depth}, \[982], 987, 991, 1002, 1003, 1004, 1008, 1010.
\:\9{page\_depth\_}{\.{\\pagedepth} primitive}, \[983].
\:\9{page\_fil\_stretch\_}{\.{\\pagefilstretch} primitive}, \[983].
\:\9{page\_fill\_stretch\_}{\.{\\pagefillstretch} primitive}, \[983].
\:\9{page\_filll\_stretch\_}{\.{\\pagefilllstretch} primitive}, \[983].
\:\\{page\_goal}, 980, \[982], 986, 987, 1005, 1006, 1007, 1008, 1009, 1010.
\:\9{page\_goal\_}{\.{\\pagegoal} primitive}, \[983].
\:\\{page\_head}, \[162], 215, 980, 986, 988, 991, 1014, 1017, 1023, 1026, 1054.
\:\\{page\_ins\_head}, \[162], 981, 986, 1005, 1008, 1018, 1019, 1020.
\:\\{page\_ins\_node\_size}, \[981], 1009, 1019.
\:\\{page\_loc}, \[638], 640.
\:\\{page\_max\_depth}, \[980], 982, 987, 991, 1003, 1017.
\:\\{page\_shrink}, \[982], 985, 1004, 1007, 1008, 1009.
\:\9{page\_shrink\_}{\.{\\pageshrink} primitive}, \[983].
\:\\{page\_so\_far}, 421, \[982], 985, 987, 1004, 1007, 1009, 1245.
\:\\{page\_stack}, \[304\*], 328\*, 329\*.
\:\9{page\_stretch\_}{\.{\\pagestretch} primitive}, \[983].
\:\\{page\_tail}, 215, \[980], 986, 991, 998, 1000, 1017, 1023, 1026, 1054.
\:\\{page\_total}, \[982], 985, 1002, 1003, 1004, 1007, 1008, 1010.
\:\9{page\_total\_}{\.{\\pagetotal} primitive}, \[983].
\:\\{panicking}, \[165], 166, 1031, 1339.
\:\9{par\_}{\.{\\par} primitive}, \[334].
\:\\{par\_end}, \[207], 334, 335, 1046\*, 1094.
\:\\{par\_fill\_skip}, \[224], 816.
\:\9{par\_fill\_skip\_}{\.{\\parfillskip} primitive}, \[226].
\:\\{par\_fill\_skip\_code}, \[224], 225, 226, 816.
\:\\{par\_indent}, \[247], 1091, 1093.
\:\9{par\_indent\_}{\.{\\parindent} primitive}, \[248].
\:\\{par\_indent\_code}, \[247], 248.
\:\\{par\_loc}, \[333], 334, 351, 1313, 1314.
\:\9{par\_shape\_}{\.{\\parshape} primitive}, \[265\*].
\:\\{par\_shape\_loc}, \[230], 232\*, 233, 1070, 1248.
\:\\{par\_shape\_ptr}, \[230], 232\*, 233, 423, 814, 847, 848, 850, 889, 1070,
1149, 1249.
\:\\{par\_skip}, \[224], 1091.
\:\9{par\_skip\_}{\.{\\parskip} primitive}, \[226].
\:\\{par\_skip\_code}, \[224], 225, 226, 1091.
\:\\{par\_token}, \[333], 334, 339, 392, 395, 399, 1095, 1314.
\:\.{Paragraph ended before...}, 396.
\:\\{param}, 542, 547, \[558].
\:\\{param\_base}, \[550], 552, 558, 566, 574, 575, 576, 578, 580, 700, 701,
1042, 1322, 1323.
\:\\{param\_end}, \[558].
\:\\{param\_ptr}, \[308], 323, 324, 331, 390.
\:\\{param\_size}, \[11\*], 308, 390, 1334.
\:\\{param\_stack}, 307, \[308], 324, 359, 388, 389, 390.
\:\\{param\_start}, \[307], 323, 324, 359.
\:\\{parameter}, \[307], 314, 359.
\:{parameters for symbols}, 700, 701.
\:\.{Parameters...consecutively}, 476.
\:\9{PASCAL H}{\ph}, \[3], 27\*.
\:\9{PASCAL}{\PASCAL}, 1, 10, 693, 764.
\:\\{pass\_number}, \[821], 845, 864.
\:\\{pass\_text}, 366\*, \[494\*], 500, 509, 510.
\:\\{passive}, \[821], 845, 846, 864, 865.
\:\\{passive\_node\_size}, \[821], 845, 865.
\:\.{Patterns can be...}, 1252.
\:\9{patterns\_}{\.{\\patterns} primitive}, \[1250].
\:\\{pause\_for\_instructions}, 96, \[98].
\:\\{pausing}, \[236], 363\*.
\:\9{pausing\_}{\.{\\pausing} primitive}, \[238].
\:\\{pausing\_code}, \[236], 237, 238.
\:\.{pc}, 458.
\:\\{pen}, \[726], 761, 767, \[877], 890.
\:{penalties}, 1102.
\:\\{penalties}, \[726], 767.
\:\\{penalty}, \[157], 158, 194, 424, 816, 866, 973, 996, 1000, 1010, 1011,
1013.
\:\9{penalty\_}{\.{\\penalty} primitive}, \[265\*].
\:\\{penalty\_node}, \[157], 158, 183\*, 202, 206, 424, 730, 761, 767, 816,
817, 837, 856, 866, 879, 899\*, 968, 973, 996, 1000, 1010, 1011, 1013, 1107.
\:\\{pg\_field}, \[212], 213, 219, 422, 1244.
\:\\{pi}, \[829], 831, 851, 856, 859, \[970], 972, 973, 974, \[994], 1000,
1005, 1006.
\:\.{plain}, 521\*, 524, 1331.
\:{Plass, Michael Frederick}, 2\*, 813.
\:\.{Please type...}, 360, 530\*.
\:\.{Please use \\mathaccent...}, 1166.
\:\.{PLtoTF}, 561.
\:\.{plus}, 462.
\:\\{point\_token}, \[438], 440\*, 448\*, 452.
\:\\{pointer}, \[115], 116\*, 118, 120, 123, 124, 125, 130, 131, 136, 139, 144,
145, 147, 151, 152, 153, 154, 156, 158, 165, 167, 172, 198, 200, 201, 202, 204,
212, 218, 252, 256, 259, 263, 275, 276, 277, 278, 279, 281, 284, 295, 297, 305,
306, 308, 323, 325, 333, 336\*, 366\*, 382, 388, 389, 407\*, 461, 463, 464,
465, 473, 482, 489, 497, 498, 549, 560, 582\*, 592, 605, 607, 615, 619, 629,
638, 647, 649, 668, 679, 686, 688, 689, 691, 692, 704, 705, 706, 709, 711, 715,
716, 717, 719, 720, 722, 726, 734, 735, 736, 737, 738, 743, 749, 752, 756, 762,
770, 772, 774, 787, 791, 799, 800, 814, 821, 826, 828, 829, 830, 833, 862, 872,
877, 892, 901, 906, 912, 926, 934, 968, 970, 977, 980, 982, 993, 994, 1012,
1032, 1043, 1064, 1068\*, 1074, 1075, 1079, 1086, 1093, 1101, 1105, 1110, 1113,
1119, 1123, 1138, 1151, 1155, 1160, 1174, 1176, 1184, 1191, 1194, 1198, 1211,
1236, 1257, 1288, 1293, 1302, 1303, 1345, 1348, 1349, 1355, 1368, 1370, 1373.
\:{Poirot, Hercule}, 1283.
\:\\{pool\_file}, 47, \[50], 51, 52, 53.
\:\\{pool\_name}, \[11\*], 51.
\:\\{pool\_pointer}, \[38], 39, 45, 46, 59, 60, 69, 70, 264, 407\*, 464, 513\*,
519\*, 530\*, 602, 638, 929, 934, 1368.
\:\\{pool\_ptr}, 38, \[39], 41, 42, 43, 44, 47, 52, 58, 70, 84\*, 198, 464, 516%
\*, 517\*, 525\*, 617, 642\*, 1309, 1310, 1332, 1334, 1339, 1368.
\:\\{pool\_size}, \[11\*], 38, 42, 52, 58, 198, 525\*, 642\*, 1310, 1334, 1339,
1368.
\:\\{pop}, 584, 585, \[586], 590, 601, 608.
\:\\{pop\_alignment}, \[772], 800.
\:\\{pop\_input}, \[322], 324, 329\*.
\:\\{pop\_nest}, \[217], 796, 799, 812, 816, 1026, 1086, 1096, 1100, 1119,
1145, 1168, 1184, 1206.
\:\\{positive}, \[107].
\:\\{post}, 583, 585, \[586], 590, 591, 642\*.
\:\\{post\_break}, \[145], 175, 195, 202, 206, 840, 858, 882, 884, 916, 1119.
\:\\{post\_display\_penalty}, \[236], 1205, 1206.
\:\9{post\_display\_penalty\_}{\.{\\postdisplaypenalty} primitive}, \[238].
\:\\{post\_display\_penalty\_code}, \[236], 237, 238.
\:\\{post\_line\_break}, 876, \[877].
\:\\{post\_post}, 585, \[586], 590, 591, 642\*.
\:\\{pre}, 583, 585, \[586], 617.
\:\\{pre\_break}, \[145], 175, 195, 202, 206, 858, 870, 882, 885, 915, 918,
1117, 1119.
\:\\{pre\_display\_penalty}, \[236], 1203, 1206.
\:\9{pre\_display\_penalty\_}{\.{\\predisplaypenalty} primitive}, \[238].
\:\\{pre\_display\_penalty\_code}, \[236], 237, 238.
\:\\{pre\_display\_size}, \[247], 1138, 1145, 1148, 1203.
\:\9{pre\_display\_size\_}{\.{\\predisplaysize} primitive}, \[248].
\:\\{pre\_display\_size\_code}, \[247], 248, 1145.
\:{preamble}, 768, 774.
\:\\{preamble}, \[770], 771, 772, 777, 786, 801, 804.
\:{preamble of \.{DVI} file}, 617.
\:\\{precedes\_break}, \[148], 868, 973, 1000.
\:\\{prefix}, \[209\*], 1208, 1209, 1210, 1211.
\:\\{prefixed\_command}, 1210, \[1211], 1270.
\:\\{prepare\_mag}, \[288], 457, 617, 642\*, 1333\*.
\:\\{pretolerance}, \[236], 828, 863.
\:\9{pretolerance\_}{\.{\\pretolerance} primitive}, \[238].
\:\\{pretolerance\_code}, \[236], 237, 238.
\:\\{prev\_break}, \[821], 845, 846, 877, 878.
\:\\{prev\_depth}, 212, \[213], 215, 679, 775, 786, 787, 1025, 1056, 1083,
1099, 1167, 1206, 1242, 1243.
\:\9{prev\_depth\_}{\.{\\prevdepth} primitive}, \[416].
\:\\{prev\_dp}, \[970], 972, 973, 974, 976.
\:\\{prev\_graf}, 212, \[213], 215, 216, 814, 864, 877, 890, 1091, 1149, 1200,
1242.
\:\9{prev\_graf\_}{\.{\\prevgraf} primitive}, \[265\*].
\:\\{prev\_p}, \[862], 863, 866, 867\*, 868, \[968], 969, \[970], 973, \[1012],
1014, 1017, 1022.
\:\\{prev\_prev\_r}, \[830], 832, 843, 844, 860.
\:\\{prev\_r}, \[829], 830, 832, 843, 844, 845, 851, 854, 860.
\:\\{primitive}, 226, 230, 238, 248, \[264], 265\*, 266\*, 298, 334, 376, 384,
411, 416, 468, 487, 491, 553, 780, 983, 1052, 1058, 1071, 1088, 1107, 1114,
1141, 1156, 1169, 1178, 1188, 1208, 1219, 1222, 1230, 1250, 1254, 1262, 1272,
1277, 1286, 1291, 1331, 1332, 1344.
\:\\{print}, 54, \[59], 60, 61, 62, 63, 68, 70, 71\*, 73, 84\*, 85, 86, 89, 91,
94, 95, 175, 177, 178, 182, 183\*, 184, 185, 186, 187, 188, 190, 191, 192, 193,
195, 211, 218, 219, 225, 233, 234, 237, 247, 251, 262, 263, 284, 288, 294, 298,
299, 306, 313\*, 317, 318, 323, 336\*, 338, 339, 341\*, 363\*, 366\*, 373, 395,
396, 398, 400, 407\*, 428, 440\*, 448\*, 454, 456, 459, 465, 472, 502, 509, 518%
\*, 530\*, 534, 535, 536, 537, 561, 567, 579, 581, 617, 638, 639, 642\*, 660,
663\*, 666, 674, 675\*, 677, 692, 694, 697, 723, 776, 846, 856, 936, 978, 985,
986, 987, 1006, 1011, 1015, 1024, 1049, 1064, 1095, 1132, 1166, 1213, 1232,
1237, 1257, 1259, 1261, 1280, 1295, 1296, 1298, 1309, 1311, 1318, 1320, 1322,
1324, 1328, 1333\*, 1334, 1335\*, 1338, 1339, 1346, 1356.
\:\\{print\_ASCII}, \[68], 174\*, 176\*, 298, 581, 691, 723.
\:\\{print\_char}, \[58], 59, 60, 64, 65, 66, 67, 68, 69, 70, 82, 84\*, 91, 94,
95, 103, 114, 171, 172, 174\*, 175, 176\*, 177, 178, 184, 186, 187, 188, 189,
190, 191, 193, 219, 223, 229, 233, 234, 235, 242, 251, 252, 255, 262, 284, 285,
294, 296, 299, 306, 313\*, 317, 341\*, 362, 363\*, 366\*, 407\*, 440\*, 448\*,
472, 509, 536, 537, 561, 581, 617, 638, 639, 642\*, 691, 723, 846, 856, 933,
1006, 1011, 1065, 1069, 1212, 1213, 1280, 1294, 1296, 1311, 1320, 1322, 1324,
1328, 1333\*, 1335\*, 1340, 1355, 1356.
\:\\{print\_cmd\_chr}, 223, 233, 266\*, 296, \[298], 299, 323, 336\*, 341\*,
418, 428, 503, 510, 1049, 1066, 1128, 1212, 1213, 1237, 1335\*, 1339.
\:\\{print\_cs}, \[262], 293, 314, 341\*, 401.
\:\\{print\_current\_string}, \[70], 182, 692.
\:\\{print\_delimiter}, \[691], 696, 697.
\:\\{print\_err}, 72, \[73], 93, 94, 95, 98, 288, 336\*, 338, 346, 370, 373,
395, 396, 398, 403, 408, 415, 418, 428, 432, 433, 434, 435\*, 436, 437, 442,
445, 446, 454, 456, 459, 460, 475, 476, 479, 486, 500, 503, 510, 530\*, 535,
561, 577, 579, 641, 723, 776, 783, 784, 792, 826, 936, 937, 961, 962, 963, 976,
978, 993, 1004, 1009, 1015, 1024, 1027, 1028, 1047, 1049, 1064, 1066, 1068\*,
1069, 1078, 1082, 1084, 1095, 1099, 1110, 1120, 1121, 1127, 1128, 1129, 1132,
1135, 1159, 1161, 1166, 1177, 1183, 1192, 1195, 1197, 1207, 1212, 1213, 1215,
1225, 1232, 1236, 1237, 1243, 1244, 1252, 1258, 1259, 1283, 1298, 1304, 1372.
\:\\{print\_esc}, \[63], 86, 176\*, 184, 187, 188, 189, 190, 191, 192, 194,
195, 196, 197, 225, 227, 229, 231, 233, 234, 235, 237, 239, 242, 247, 249, 251,
262, 263, 266\*, 267, 292, 293, 294, 323, 335, 373, 377, 385, 412, 417, 428,
469, 486, 488, 492, 500, 579, 691, 694, 695, 696, 697, 699, 776, 781, 792, 856,
936, 961, 978, 984, 986, 1009, 1015, 1028, 1053, 1059, 1065, 1069, 1072, 1089,
1095, 1099, 1108, 1115, 1120, 1129, 1132, 1135, 1143, 1157, 1166, 1179, 1189,
1192, 1209, 1213, 1220, 1223, 1231, 1244, 1251, 1255, 1263, 1273, 1278, 1287,
1292, 1295, 1322, 1335\*, 1346, 1355, 1356.
\:\\{print\_fam\_and\_char}, \[691], 692, 696.
\:\\{print\_file\_name}, \[518\*], 530\*, 535, 561, 1322, 1356.
\:\\{print\_font\_and\_char}, \[176\*], 183\*, 193.
\:\\{print\_glue}, \[177], 178, 185, 186.
\:\\{print\_hex}, \[67], 68, 176\*, 691, 1223.
\:\\{print\_int}, \[65], 68, 84\*, 91, 94, 103, 114, 168, 169, 170, 171, 172,
185, 188, 194, 195, 218, 219, 227, 229, 231, 233, 234, 235, 239, 242, 249, 251,
255, 285, 288, 313\*, 336\*, 400, 465, 472, 509, 536, 561, 579, 617, 638, 639,
642\*, 660, 663\*, 667, 674, 675\*, 678, 691, 723, 846, 856, 933, 986, 1006,
1009, 1011, 1024, 1028, 1099, 1232, 1296, 1309, 1311, 1318, 1320, 1324, 1328,
1335\*, 1339, 1355.
\:\\{print\_length\_param}, \[247], 249, 251.
\:\\{print\_ln}, \[57], 58, 59, 60, 61, 62, 71\*, 86, 89, 90, 114, 182, 198,
218, 236, 245, 296, 306, 314, 317, 330, 360, 363\*, 401, 484, 534, 537, 638,
639, 660, 663\*, 666, 667, 674, 675\*, 677, 678, 692, 986, 1265, 1280, 1309,
1311, 1318, 1320, 1324, 1340, 1370.
\:\\{print\_locs}, \[167].
\:\\{print\_mark}, \[176\*], 196, 1356.
\:\\{print\_meaning}, \[296], 472, 1294.
\:\\{print\_mode}, \[211], 218, 299, 1049.
\:\\{print\_nl}, \[62], 73, 82, 85, 90, 168, 169, 170, 171, 172, 218, 219, 245,
255, 285, 288, 299, 306, 313\*, 314, 323, 341\*, 360, 400, 530\*, 534, 581,
638, 639, 641, 642\*, 660, 666, 667, 674, 677, 678, 846, 856, 857, 863, 933,
986, 987, 992, 1006, 1011, 1121, 1294, 1296, 1297, 1322, 1324, 1328, 1333\*,
1335\*, 1338, 1370.
\:\\{print\_param}, \[237], 239, 242.
\:\\{print\_plus}, \[985].
\:\\{print\_plus\_end}, \[985].
\:\\{print\_roman\_int}, \[69], 472.
\:\\{print\_rule\_dimen}, \[176\*], 187.
\:\\{print\_scaled}, \[103], 114, 176\*, 177, 178, 184, 188, 191, 192, 219,
251, 465, 472, 561, 666, 677, 697, 985, 986, 987, 1006, 1011, 1259, 1261, 1322.
\:\\{print\_size}, \[699], 723, 1231.
\:\\{print\_skip\_param}, 189, \[225], 227, 229.
\:\\{print\_spec}, \[178], 188, 189, 190, 229, 465.
\:\\{print\_style}, 690, \[694], 1170.
\:\\{print\_subsidiary\_data}, \[692], 696, 697.
\:\\{print\_the\_digs}, \[64], 65, 67.
\:\\{print\_totals}, 218, \[985], 986, 1006.
\:\\{print\_two}, \[66], 536, 617.
\:\\{print\_word}, \[114], 1339.
\:\\{print\_write\_whatsit}, \[1355], 1356.
\:\\{printed\_node}, \[821], 856, 857, 858, 864.
\:\\{privileged}, \[1051], 1054, 1130, 1140.
\:\\{prompt\_file\_name}, \[530\*], 532, 535, 537, 1328, 1374.
\:\\{prompt\_input}, \[71\*], 83, 87, 360, 484, 530\*.
\:\\{prune\_movements}, \[615], 619, 629.
\:\\{prune\_page\_top}, \[968], 977, 1021.
\:\\{pseudo}, \[54], 57, 58, 59, 60, 316.
\:\\{pseudo\_typein}, 84\*, 642\*, 1333\*, \[1377\*], 1378\*.
\:\\{pstack}, \[388], 390, 396, 400.
\:\.{pt}, 453.
\:\\{pto\_chr}, \[37\*], 363\*, 530\*, 1333\*.
\:\\{ptwr1w}, \[37\*], 530\*.
\:\\{pty}, 37\*.
\:\\{punct\_noad}, \[682], 690, 696, 698, 728, 752, 761, 1156, 1157.
\:\\{push}, 584, 585, \[586], 590, 592, 601, 608, 616, 619, 629.
\:\\{push\_alignment}, \[772], 774.
\:\\{push\_input}, \[321], 323, 325, 328\*.
\:\\{push\_math}, \[1136], 1139, 1145, 1153, 1172, 1174, 1191.
\:\\{push\_nest}, \[216], 774, 786, 787, 1025, 1083, 1091, 1099, 1117, 1119,
1136, 1167, 1200.
\:\\{put}, 26, 29, 1305.
\:\\{put\_rule}, 585, \[586], 633.
\:\\{put1}, 585, \[586].
\:\\{put2}, \[585].
\:\\{put3}, \[585].
\:\\{put4}, \[585].
\:\|{q}, \[123], \[125], \[130], \[131], \[144], \[151], \[152], \[153], %
\[167], \[172], \[202], \[204], \[218], \[275], \[292], \[315], \[336\*], \[366%
\*], \[389], \[407\*], \[461], \[463], \[464], \[465], \[473], \[482], \[497], %
\[498], \[607], \[649], \[705], \[706], \[709], \[712], \[720], \[726], \[734],
\[735], \[736], \[737], \[738], \[743], \[749], \[752], \[756], \[762], \[791],
\[800], \[826], \[830], \[862], \[877], \[901], \[906], \[934], \[947], \[953],
\[957], \[959], \[960], \[968], \[970], \[994], \[1012], \[1032], \[1043], %
\[1068\*], \[1079], \[1093], \[1105], \[1119], \[1123], \[1138], \[1184], %
\[1198], \[1211], \[1236], \[1302], \[1303], \[1348], \[1370].
\:\\{qi}, \[112\*], 564, 570, 582\*, 620\*, 907, 908, 981, 1008, 1009, 1033,
1035, 1036, 1100, 1151, 1155, 1160, 1165.
\:\\{qo}, \[112\*], 159, 174\*, 176\*, 185, 188, 554, 570, 576, 602, 620\*,
691, 708, 722, 723, 741, 755, 896\*, 897, 898, 981, 986, 1008, 1018, 1021,
1035, 1036, 1038, 1040, 1324.
\:\\{qqqq}, 110\*, \[113], 114, 550, 554, 569, 573, 574, 683, 713, 741, 752,
908, 1037, 1181, 1305, 1306.
\:\\{quad}, 547, \[558], 1146.
\:\\{quad\_code}, \[547], 558.
\:\\{quarterword}, 110\*, \[113], 144, 253, 264, 271, 276, 277, 279, 281, 298,
300, 323, 592, 681, 706, 709, 711, 712, 724, 738, 877, 906, 921, 922, 943, 944,
945, 960, 1032, 1061, 1079, 1105.
\:\\{quarterword\_diff}, \[943].
\:\\{qw}, \[560], 564, 570.
\:\|{r}, \[108], \[123], \[125], \[131], \[204], \[218], \[366\*], \[389], %
\[465], \[482], \[498], \[649], \[668], \[706], \[720], \[726], \[791], \[800],
\[829], \[862], \[877], \[901], \[906], \[960], \[970], \[994], \[1012], %
\[1032], \[1123], \[1160], \[1198], \[1236], \[1348], \[1370].
\:\\{r\_type}, \[726], 727, 728, 729, 760, 766, 767.
\:\\{radical}, \[208\*], 265\*, 266\*, 1046\*, 1162.
\:\9{radical\_}{\.{\\radical} primitive}, \[265\*].
\:\\{radical\_noad}, \[683], 690, 696, 698, 733, 761, 1163.
\:\\{radical\_noad\_size}, \[683], 698, 761, 1163.
\:\\{radix}, 366\*, \[438], 439, 440\*, 444, 445, 448\*.
\:\\{radix\_backup}, \[366\*].
\:\9{raise\_}{\.{\\raise} primitive}, \[1071].
\:{Ramshaw, Lyle Harold}, 539.
\:\\{rbrace\_ptr}, \[389], 399, 400.
\:\\{read}, 31\*, 52, 53, 485\*, 538\*, 1338, 1339.
\:\9{read\_}{\.{\\read} primitive}, \[265\*].
\:\\{read\_file}, \[480], 485\*, 486, 1275.
\:\\{read\_font\_info}, \[560], 564, 1257.
\:\\{read\_ln}, 37\*, 52, 485\*, 538\*.
\:\\{read\_open}, \[480], 481, 483, 485\*, 486, 501, 1275.
\:\\{read\_sixteen}, \[564], 565, 568.
\:\\{read\_to\_cs}, \[209\*], 265\*, 266\*, 1210, 1225.
\:\\{read\_toks}, 303, \[482], 1225.
\:\\{ready\_already}, \[1331], 1332.
\:\\{real}, 3, 109, 110\*, 182, 186, 1123, 1125\*.
\:{real addition}, 1125\*.
\:{real division}, 658, 664, 673, 676, 810, 811, 1123, 1125\*.
\:{real multiplication}, 114, 186, 625, 634, 809, 1125\*.
\:\\{rebox}, \[715], 744, 750.
\:\\{reconstitute}, 905, \[906], 913, 915, 916.
\:{recursion}, 76, 78, 173, 180, 198, 202, 203, 366\*, 402, 527, 592, 618, 692,
719, 948, 957, 959, 1375.
\:\\{ref\_count}, \[389], 390, 401.
\:{reference counts}, 150, 200, 201, 203, 275, 291, 307.
\:\\{register}, \[209\*], 411, 412, 413, 1210, 1235, 1236, 1237.
\:\\{rel\_noad}, \[682], 690, 696, 698, 728, 761, 767, 1156, 1157.
\:\\{rel\_penalty}, \[236], 682, 761.
\:\9{rel\_penalty\_}{\.{\\relpenalty} primitive}, \[238].
\:\\{rel\_penalty\_code}, \[236], 237, 238.
\:\\{relax}, \[207], 265\*, 266\*, 358, 404, 506, 1045, 1224.
\:\9{relax\_}{\.{\\relax} primitive}, \[265\*].
\:\\{rem\_byte}, \[545], 554, 557, 570, 708, 713, 740, 749, 753, 909, 1040.
\:\\{remainder}, \[104], 106, 107, 457, 458, \[543], 544, 545, 716, 717.
\:\\{remove\_item}, \[208\*], 1104, 1107, 1108.
\:\\{rep}, \[546].
\:\\{replace\_count}, \[145], 175, 195, 840, 858, 882, 883, 917, 1081, 1105,
1120.
\:\\{report\_illegal\_case}, 1045, \[1050], 1051, 1243.
\:\\{rescan}, \[37\*].
\:\\{reset}, 26, 27\*.
\:\\{reset\_OK}, \[27\*].
\:\\{restart}, \[15], 125, 126, 341\*, 346, 357, 359, 360, 362, 380, 752, 753,
782, 785, 789, 1151, 1215.
\:\\{restore\_old\_value}, \[268], 276, 282.
\:\\{restore\_trace}, 283, \[284].
\:\\{restore\_zero}, \[268], 276, 278.
\:\\{result}, \[45], \[46].
\:\\{resume\_after\_display}, 800, 1199, \[1200], 1206.
\:\\{reswitch}, \[15], 176\*, 341\*, 343, 352, 463, 619, 620\*, 649, 651, 652,
726, 728, 934, 935, 1029, 1030, 1036, 1045, 1138, 1147\*, 1151.
\:\&{return}, 15, \[16].
\:\\{rewrite}, 26, 27\*.
\:\\{rewrite\_OK}, \[27\*].
\:\\{rh}, 110\*, \[113], 114, 118, 221, 234, 256, 268, 685, 921, 966.
\:\9{right\_}{\.{\\right} primitive}, \[1188].
\:\\{right\_brace}, \[207], 289, 294, 298, 347, 357, 389, 442, 474, 477, 785,
935, 961, 1067, 1252.
\:\\{right\_brace\_limit}, \[289], 325, 392, 399, 400, 474, 477.
\:\\{right\_brace\_token}, \[289], 339, 1065, 1127, 1226, 1371.
\:\\{right\_delimiter}, \[683], 697, 748, 1181, 1182.
\:\\{right\_noad}, \[687], 690, 696, 698, 725, 728, 760, 761, 762, 1184, 1188,
1191.
\:\\{right\_ptr}, \[605], 606, 607, 615.
\:\\{right\_skip}, \[224], 827, 880, 881.
\:\9{right\_skip\_}{\.{\\rightskip} primitive}, \[226].
\:\\{right\_skip\_code}, \[224], 225, 226, 881, 886.
\:\\{right1}, 585, \[586], 607, 610, 616.
\:\\{right2}, 585, 610.
\:\\{right3}, 585, 610.
\:\\{right4}, 585, 610.
\:\\{rlink}, \[124], 125, 126, 127, 129, 130, 131, 132, 145, 149, 164, 169,
772, 819, 821, 1311, 1312.
\:\9{roman\_numeral\_}{\.{\\romannumeral} primitive}, \[468].
\:\\{roman\_numeral\_code}, \[468], 469, 471, 472.
\:\\{round}, 114, 186, 625, 634, 809, 1125\*.
\:\\{round\_decimals}, \[102], 103, 452.
\:\\{rover}, \[124], 125, 126, 127, 128, 129, 130, 131, 132, 164, 169, 1311,
1312.
\:\\{rule\_dp}, \[592], 622, 624, 626, 631, 633, 635.
\:\\{rule\_ht}, \[592], 622, 624, 626, 631, 633, 634, 635, 636.
\:\\{rule\_node}, \[138], 139, 148, 175, 183\*, 202, 206, 622, 626, 631, 635,
651, 653, 669, 670, 730, 761, 805, 841\*, 842\*, 866, 871\*, 968, 973, 1000,
1074, 1087, 1121, 1147\*.
\:\\{rule\_node\_size}, \[138], 139, 202, 206.
\:\\{rule\_save}, \[800], 804.
\:\\{rule\_wd}, \[592], 622, 624, 625, 626, 627, 631, 633, 635.
\:{rules aligning with characters}, 589.
\:\\{runaway}, 120, \[306], 338, 396, 486.
\:\.{Runaway...}, 306.
\:\|{s}, \[37\*], \[45], \[46], \[58], \[59], \[60], \[62], \[63], \[93], %
\[94], \[95], \[103], \[108], \[125], \[130], \[147], \[177], \[178], \[264], %
\[284], \[389], \[407\*], \[473], \[482], \[529], \[530\*], \[560], \[638], %
\[649], \[668], \[688], \[699], \[706], \[720], \[726], \[738], \[791], \[800],
\[830], \[862], \[877], \[901], \[906], \[934], \[960], \[987], \[1012], %
\[1032], \[1060], \[1061], \[1123], \[1138], \[1198], \[1236], \[1257], %
\[1279], \[1349], \[1355].
\:\\{save\_cond\_ptr}, \[498], 500, 509.
\:\\{save\_cs\_ptr}, \[774], 777.
\:\\{save\_cur\_val}, \[450], 455.
\:\\{save\_for\_after}, \[280], 1271.
\:\\{save\_h}, \[619], 623, 627, 628, \[629], 632, 637.
\:\\{save\_index}, \[268], 269, 274, 276, 280, 282.
\:\\{save\_level}, \[268], 274, 276, 280, 282.
\:\\{save\_link}, \[830], 857.
\:\\{save\_loc}, \[619], \[629].
\:\\{save\_ptr}, 268, \[271], 272, 273, 274, 276, 280, 282, 283, 285, 645, 804,
1063\*, 1068\*, 1083, 1086, 1099, 1100, 1117, 1120, 1142, 1153, 1168, 1172,
1174, 1186, 1194, 1304, 1335\*.
\:\\{save\_scanner\_status}, \[366\*], 369, \[389], \[470], 471, \[494\*], %
\[498], 507.
\:\\{save\_size}, \[11\*], 111, 271, 273, 1334.
\:\\{save\_split\_top\_skip}, \[1012], 1014.
\:\\{save\_stack}, 203, 268, 270, \[271], 273, 274, 275, 276, 277, 281, 282,
283, 285, 300, 489, 645, 768, 1062, 1071, 1073, 1131, 1140, 1150, 1153, 1339.
\:\\{save\_style}, \[720], \[726], 754.
\:\\{save\_type}, \[268], 274, 276, 280, 282.
\:\\{save\_v}, \[619], 623, 628, \[629], 632, 636, 637.
\:\\{save\_vbadness}, \[1012], 1017.
\:\\{save\_vfuzz}, \[1012], 1017.
\:\\{save\_warning\_index}, \[389].
\:\\{saved}, \[274], 645, 804, 1063\*, 1073, 1075, 1076, 1077, 1078, 1079,
1083, 1084, 1086, 1099, 1100, 1117, 1119, 1142, 1153, 1168, 1172, 1174, 1186,
1194, 1241, 1335\*.
\:\\{sc}, 110\*, \[113], 114, 135, 150, 159, 164, 247, 250, 251, 413, 420, 425,
550, 552, 554, 557, 558, 571, 573, 575, 580, 700, 701, 822, 823, 832, 843, 844,
848, 850, 860, 861, 889, 1042, 1149, 1247, 1248, 1253.
\:\\{scaled}, \[101], 102, 103, 104, 105, 106, 107, 108, 110\*, 113, 147, 150,
156, 176\*, 177, 447, 448\*, 450, 453, 548, 549, 560, 584, 592, 607, 616, 619,
629, 646, 649, 668, 679, 704, 705, 706, 712, 715, 716, 717, 719, 726, 735, 736,
737, 738, 743, 749, 756, 762, 791, 800, 823, 830, 833, 839, 847, 877, 906, 970,
971, 977, 980, 982, 994, 1012, 1068\*, 1086, 1123, 1138, 1198, 1257.
\:\.{scaled}, 1258.
\:\\{scaled\_base}, \[247], 249, 251, 1224, 1237.
\:\\{scan\_box}, 1073, \[1084], 1241.
\:\\{scan\_char\_num}, \[435\*], 935, 1030, 1036, 1123, 1124\*, 1151, 1154,
1224.
\:\\{scan\_delimiter}, \[1160], 1163, 1182, 1183, 1191, 1192.
\:\\{scan\_dimen}, 410, 440\*, 447, \[448\*], 461, 462, 1061.
\:\\{scan\_eight\_bit\_int}, 415, 420, 427, \[433], 505, 1079, 1082, 1099,
1110, 1224, 1226, 1227, 1237, 1241, 1247, 1296.
\:\\{scan\_fifteen\_bit\_int}, \[436], 1151, 1154, 1165, 1224.
\:\\{scan\_file\_name}, 265\*, \[526], 527, 537, 1257, 1275, 1351.
\:\\{scan\_font\_ident}, 415, 426, 471, \[577], 578, 1234, 1253.
\:\\{scan\_four\_bit\_int}, \[434], 501, 577, 1234, 1275, 1350.
\:\\{scan\_glue}, 410, \[461], 782, 1060, 1228, 1238.
\:\\{scan\_int}, 409, 410, 432, 433, 434, 435\*, 436, 437, 438, \[440\*], 447,
448\*, 461, 471, 503, 504, 509, 578, 1103, 1225, 1228, 1232, 1238, 1240, 1243,
1244, 1246, 1248, 1253, 1258, 1350.
\:\\{scan\_keyword}, 162, \[407\*], 453, 454, 455, 456, 458, 462, 463, 645,
1082, 1225, 1236, 1258.
\:\\{scan\_left\_brace}, \[403], 473, 645, 785, 934, 960, 1025, 1099, 1117,
1119, 1153, 1172, 1174.
\:\\{scan\_math}, 1150, \[1151], 1158, 1163, 1165, 1176.
\:\\{scan\_normal\_dimen}, \[448\*], 463, 503, 645, 1073, 1082, 1182, 1183,
1228, 1238, 1243, 1245, 1247, 1248, 1253, 1259.
\:\\{scan\_optional\_equals}, \[405], 782, 1224, 1226, 1228, 1232, 1234, 1236,
1241, 1243, 1244, 1245, 1246, 1247, 1248, 1253, 1257, 1275, 1351.
\:\\{scan\_rule\_spec}, \[463], 1056, 1084.
\:\\{scan\_seven\_bit\_int}, 414, \[432], 1232.
\:\\{scan\_something\_internal}, 409, 410, \[413], 432, 440\*, 449, 451, 455,
461, 465.
\:\\{scan\_spec}, \[645], 768, 774, 1071, 1083, 1167.
\:\\{scan\_toks}, 291, 464, \[473], 1101, 1218, 1226, 1279, 1288, 1352, 1354,
1371.
\:\\{scan\_twenty\_seven\_bit\_int}, \[437], 1151, 1154, 1160.
\:\\{scan\_xchar\_num}, \[435\*], 1122\*, 1124\*.
\:\\{scanned\_result}, \[413], 414, 415, 418, 422, 425, 426, 428.
\:\\{scanned\_result\_end}, \[413].
\:\\{scanner\_status}, \[305], 306, 331, 336\*, 339, 366\*, 369, 389, 391, 470,
471, 473, 482, 494\*, 498, 507, 777, 789.
\:\9{script\_font\_}{\.{\\scriptfont} primitive}, \[1230].
\:\\{script\_mlist}, \[689], 695, 698, 731, 1174.
\:\9{script\_script\_font\_}{\.{\\scriptscriptfont} primitive}, \[1230].
\:\\{script\_script\_mlist}, \[689], 695, 698, 731, 1174.
\:\\{script\_script\_size}, \[699], 756, 1195, 1230.
\:\\{script\_script\_style}, \[688], 694, 731, 1169.
\:\9{script\_script\_style\_}{\.{\\scriptscriptstyle} primitive}, \[1169].
\:\\{script\_size}, \[699], 756, 1195, 1230.
\:\\{script\_space}, \[247], 757, 758, 759.
\:\9{script\_space\_}{\.{\\scriptspace} primitive}, \[248].
\:\\{script\_space\_code}, \[247], 248.
\:\\{script\_style}, \[688], 694, 702, 703, 731, 756, 762, 766, 1169.
\:\9{script\_style\_}{\.{\\scriptstyle} primitive}, \[1169].
\:\\{scripts\_allowed}, \[687], 1176.
\:\\{scroll\_mode}, 71\*, \[73], 84\*, 86, 93, 530\*, 535, 1262, 1263, 1281.
\:\9{scroll\_mode\_}{\.{\\scrollmode} primitive}, \[1262].
\:\\{search\_mem}, 165, \[172], 255, 1339.
\:\\{second\_indent}, \[847], 848, 849, 889.
\:\\{second\_pass}, \[828], 854, 863, 866, 873.
\:\\{second\_width}, \[847], 848, 849, 850, 889.
\:{Sedgewick, Robert}, 2\*.
\:\.{see the transcript file...}, 1335\*.
\:\\{selector}, \[54], 55, 57, 58, 59, 60, 62, 71\*, 75, 84\*, 86, 90, 92, 98,
245, 311, 312, 316, 360, 363\*, 465, 470, 534, 617, 638, 642\*, 1257, 1265,
1279, 1298, 1328, 1333\*, 1335\*, 1368, 1370.
\:\\{semi\_simple\_group}, \[269], 1063\*, 1065, 1068\*, 1069, 1335\*.
\:\\{serial}, \[821], 845, 846, 856.
\:\\{set\_aux}, \[209\*], 413, 416, 417, 418, 1210, 1242.
\:\\{set\_box}, \[209\*], 265\*, 266\*, 1210, 1241.
\:\9{set\_box\_}{\.{\\setbox} primitive}, \[265\*].
\:\\{set\_box\_dimen}, \[209\*], 413, 416, 417, 1210, 1242.
\:\\{set\_break\_width\_to\_background}, \[837].
\:\\{set\_char\_0}, 585, \[586], 620\*.
\:\\{set\_conversion}, \[458].
\:\\{set\_conversion\_end}, \[458].
\:\\{set\_font}, \[209\*], 413, 553, 577, 1210, 1217, 1257, 1261.
\:\\{set\_glue\_ratio\_one}, \[109], 664, 676, 810, 811.
\:\\{set\_glue\_ratio\_zero}, \[109], 136, 657, 658, 664, 672, 673, 676, 810,
811.
\:\\{set\_height\_zero}, \[970].
\:\\{set\_interaction}, \[209\*], 1210, 1262, 1263, 1264.
\:\\{set\_math\_char}, 1154, \[1155].
\:\\{set\_page\_dimen}, \[209\*], 413, 982, 983, 984, 1210, 1242.
\:\\{set\_page\_int}, \[209\*], 413, 416, 417, 1210, 1242.
\:\\{set\_page\_so\_far\_zero}, \[987].
\:\\{set\_prev\_graf}, \[209\*], 265\*, 266\*, 413, 1210, 1242.
\:\\{set\_rule}, 583, 585, \[586], 624.
\:\\{set\_shape}, \[209\*], 265\*, 266\*, 413, 1210, 1248.
\:\\{set\_trick\_count}, \[316], 317, 318, 320.
\:\\{set1}, 585, \[586], 620\*.
\:\\{set2}, \[585].
\:\\{set3}, \[585].
\:\\{set4}, \[585].
\:\\{sf\_code}, \[230], 232\*, 1034.
\:\9{sf\_code\_}{\.{\\sfcode} primitive}, \[1230].
\:\\{sf\_code\_base}, \[230], 235, 1230, 1231, 1233.
\:\\{shape\_ref}, \[210], 232\*, 275, 1070, 1248.
\:\\{shift\_amount}, \[135], 136, 159, 184, 623, 628, 632, 637, 649, 653, 668,
670, 681, 706, 720, 737, 738, 749, 750, 756, 757, 759, 799, 807, 808, 889,
1076, 1081, 1125\*, 1146, 1203, 1204, 1205.
\:\\{shift\_case}, 1285, \[1288].
\:\\{shift\_down}, \[743], 744, 745, 746, 747, \[749], 751, \[756], 757, 759.
\:\\{shift\_up}, \[743], 744, 745, 746, 747, \[749], 751, \[756], 758, 759.
\:\\{ship\_out}, 211, 592, \[638], 644, 1023, 1075.
\:\9{ship\_out\_}{\.{\\shipout} primitive}, \[1071].
\:\\{ship\_out\_flag}, \[1071], 1075.
\:\\{short\_display}, 173, \[174\*], 175, 193, 663\*, 857, 1339.
\:\\{short\_real}, 109, 110\*.
\:\\{shortcut}, 447, \[448\*].
\:\\{shortfall}, \[830], 851, 852, 853.
\:\\{shorthand\_def}, \[209\*], 1210, 1222, 1223, 1224.
\:\9{show\_}{\.{\\show} primitive}, \[1291].
\:\\{show\_activities}, \[218], 1293.
\:\\{show\_box}, 180, 182, \[198], 218, 219, 236, 638, 641, 663\*, 675\*, 986,
992, 1121, 1296, 1339.
\:\9{show\_box\_}{\.{\\showbox} primitive}, \[1291].
\:\\{show\_box\_breadth}, \[236], 1339.
\:\9{show\_box\_breadth\_}{\.{\\showboxbreadth} primitive}, \[238].
\:\\{show\_box\_breadth\_code}, \[236], 237, 238.
\:\\{show\_box\_code}, \[1291], 1292, 1293.
\:\\{show\_box\_depth}, \[236], 1339.
\:\9{show\_box\_depth\_}{\.{\\showboxdepth} primitive}, \[238].
\:\\{show\_box\_depth\_code}, \[236], 237, 238.
\:\\{show\_code}, \[1291], 1293.
\:\\{show\_context}, 54, 78, 82, 88, 310, \[311], 318, 530\*, 535, 537.
\:\\{show\_cur\_cmd\_chr}, \[299], 367, 1031.
\:\\{show\_eqtb}, \[252], 284.
\:\\{show\_info}, 692, \[693].
\:\\{show\_lists}, \[1291], 1292, 1293.
\:\9{show\_lists\_}{\.{\\showlists} primitive}, \[1291].
\:\\{show\_node\_list}, 173, 176\*, 180, 181, \[182], 195, 198, 233, 690, 692,
693, 695, 1339.
\:\9{show\_the\_}{\.{\\showthe} primitive}, \[1291].
\:\\{show\_the\_code}, \[1291], 1292.
\:\\{show\_token\_list}, 176\*, 223, 233, \[292], 295, 306, 319, 320, 400,
1339, 1368, 1370.
\:\\{show\_whatever}, 1290, \[1293].
\:\\{shown\_mode}, \[213], 215, 299.
\:\\{shrink}, \[150], 151, 164, 178, 431, 462, 625, 634, 656, 671, 716, 809,
825, 827, 838, 869, 976, 1004, 1009, 1042, 1044, 1148, 1229, 1239, 1240.
\:\\{shrink\_order}, \[150], 164, 178, 462, 625, 634, 656, 671, 716, 809, 825,
826, 976, 1004, 1009, 1148, 1239.
\:\\{shrinking}, \[135], 186, 619, 629, 664, 676, 809, 810, 811, 1148.
\:\\{simple\_group}, \[269], 1063\*, 1068\*, 1335\*.
\:{Single-character primitives}, \[267].
\:\9{Single-character primitives -}{\quad\.{\\-}}, \[1114].
\:\9{Single-character primitives /}{\quad\.{\\/}}, \[265\*].
\:\9{Single-character primitives /}{\quad\.{\\\ }}, \[265\*].
\:\\{single\_base}, \[222], 262, 263, 264, 354, 374, 442, 1257, 1289.
\:\\{skew\_char}, 426, \[549], 552, 576, 741, 1253, 1322, 1323.
\:\9{skew\_char\_}{\.{\\skewchar} primitive}, \[1254].
\:\\{skip}, \[224], 427, 1009.
\:\9{skip\_}{\.{\\skip} primitive}, \[411].
\:\\{skip\_base}, \[224], 227, 229, 1224, 1237.
\:\\{skip\_blanks}, \[303], 344, 345, 347, 349, 354.
\:\\{skip\_code}, \[1058], 1059, 1060.
\:\9{skip\_def\_}{\.{\\skipdef} primitive}, \[1222].
\:\\{skip\_def\_code}, \[1222], 1223, 1224.
\:\\{skip\_line}, 336\*, \[493\*], 494\*.
\:\\{skip\_page}, 336\*, \[493\*], 494\*.
\:\\{skipping}, \[305], 306, 336\*, 494\*.
\:\\{slant}, 547, \[558], 575, 1123, 1125\*.
\:\\{slant\_code}, \[547], 558.
\:\\{slow\_print}, \[60], 262, 263.
\:\\{small\_char}, \[683], 691, 697, 706, 1160.
\:\\{small\_fam}, \[683], 691, 697, 706, 1160.
\:\\{small\_node\_size}, \[141], 144, 145, 147, 152, 153, 156, 158, 202, 206,
655, 721, 914, 1100, 1101, 1357, 1358.
\:\\{small\_number}, \[101], 102, 147, 152, 154, 264, 366\*, 389, 413, 438, 440%
\*, 450, 461, 470, 482, 489, 494\*, 497, 498, 523\*, 607, 649, 668, 688, 706,
719, 720, 726, 756, 762, 829, 892, 893, 905, 906, 921, 934, 944, 960, 970, 987,
1060, 1086, 1176, 1181, 1191, 1198, 1211, 1236, 1247, 1257, 1325, 1335\*, 1349,
1350, 1370, 1373.
\:\.{Sorry, I can't find...}, 524.
\:\\{sort\_avail}, \[131], 1311.
\:{sp}, 104, 587.
\:\.{sp}, 458.
\:\\{space}, 547, \[558], 752, 755, 1042.
\:\\{space\_code}, \[547], 558, 578, 1042.
\:\\{space\_factor}, 212, \[213], 786, 787, 799, 1030, 1032, 1034, 1043, 1044,
1056, 1076, 1083, 1091, 1093, 1117, 1119, 1122\*, 1123, 1196, 1200, 1242, 1243.
\:\9{space\_factor\_}{\.{\\spacefactor} primitive}, \[416].
\:\\{space\_shrink}, 547, \[558], 1042.
\:\\{space\_shrink\_code}, \[547], 558, 578.
\:\\{space\_skip}, \[224], 1041, 1043.
\:\9{space\_skip\_}{\.{\\spaceskip} primitive}, \[226].
\:\\{space\_skip\_code}, \[224], 225, 226, 1041.
\:\\{space\_stretch}, 547, \[558], 1042.
\:\\{space\_stretch\_code}, \[547], 558.
\:\\{space\_token}, \[289], 393, 464, 1215.
\:\\{spacer}, \[207], 208\*, 232\*, 289, 291, 294, 298, 303, 337, 345, 347,
348, 349, 354, 404, 406, 407\*, 443, 444, 452, 464, 783, 935, 961, 1030, 1045,
1221.
\:\9{span\_}{\.{\\span} primitive}, \[780].
\:\\{span\_code}, \[780], 781, 782, 789, 791.
\:\\{span\_count}, 136, \[159], 185, 796, 801, 808.
\:\\{span\_node\_size}, \[797], 798, 803.
\:\9{special\_}{\.{\\special} primitive}, \[1344].
\:\\{special\_node}, \[1341], 1344, 1346, 1348, 1354, 1356, 1357, 1358, 1373.
\:\\{special\_out}, \[1368], 1373.
\:\.{split}, 1011.
\:\\{split\_bot\_mark}, \[382], 383, 977, 979.
\:\9{split\_bot\_mark\_}{\.{\\splitbotmark} primitive}, \[384].
\:\\{split\_bot\_mark\_code}, \[382], 384, 385.
\:\\{split\_first\_mark}, \[382], 383, 977, 979.
\:\9{split\_first\_mark\_}{\.{\\splitfirstmark} primitive}, \[384].
\:\\{split\_first\_mark\_code}, \[382], 384, 385.
\:\\{split\_max\_depth}, 140, \[247], 977, 1068\*, 1100.
\:\9{split\_max\_depth\_}{\.{\\splitmaxdepth} primitive}, \[248].
\:\\{split\_max\_depth\_code}, \[247], 248.
\:\\{split\_top\_ptr}, \[140], 188, 202, 206, 1021, 1022, 1100.
\:\\{split\_top\_skip}, 140, \[224], 968, 977, 1012, 1014, 1021, 1100.
\:\9{split\_top\_skip\_}{\.{\\splittopskip} primitive}, \[226].
\:\\{split\_top\_skip\_code}, \[224], 225, 226, 969.
\:\\{split\_up}, \[981], 986, 1008, 1010, 1020, 1021.
\:\\{spotless}, \[76], 77, 245, 1332, 1335\*.
\:\.{spread}, 645.
\:\\{sprint\_cs}, 223, \[263], 338, 395, 396, 398, 472, 479, 484, 561, 1294.
\:{square roots}, 737.
\:\\{ss\_code}, \[1058], 1059, 1060.
\:\\{ss\_glue}, \[162], 164, 715, 1060.
\:{stack conventions}, 300.
\:\\{stack\_into\_box}, \[711], 713.
\:\\{stack\_size}, \[11\*], 301, 310, 321, 1334.
\:\\{start}, 300, \[302], 303, 307, 318, 319, 323, 324, 325, 328\*, 329\*, 331,
360, 362, 363\*, 369, 483, 485\*, 538\*.
\:\\{start\_cs}, \[341\*], 354, 355.
\:\\{start\_eq\_no}, 1140, \[1142].
\:\\{start\_field}, \[300], 302.
\:\\{start\_font\_error\_message}, \[561], 567.
\:\\{start\_here}, 5, \[1332].
\:\\{start\_input}, 366\*, 376, 378, \[537], 1337.
\:\\{start\_of\_TEX}, \[6], 1332.
\:\\{start\_par}, \[208\*], 1088, 1089, 1090\*, 1092.
\:\&{stat}, \[7\*], \[117], \[120], \[121], \[122], \[123], \[125], \[130], %
\[252], \[260], \[283], \[284], \[639], \[829], \[845], \[851], \[854], \[855],
\[863], \[987], \[1005], \[1010], \[1333\*].
\:\\{state}, 87, 300, \[302], 303, 307, 311, 312, 323, 325, 328\*, 330, 331,
337, 341\*, 343, 344, 346, 347, 349, 352, 353, 354, 390, 483, 537.
\:\\{state\_field}, \[300], 302.
\:{stomach}, 402.
\:\\{stop}, \[207], 1045, 1046\*, 1052, 1053, 1054, 1094.
\:\\{stop\_bit}, \[545], 741, 752, 908, 1037.
\:\\{stop\_flag}, \[545], 741, 752, 908, 1037.
\:\\{store\_background}, \[864].
\:\\{store\_break\_width}, \[843].
\:\\{store\_fmt\_file}, \[1302], 1335\*.
\:\\{store\_four\_quarters}, \[564], 568, 569, 573, 574.
\:\\{store\_new\_token}, \[371], 372, 393, 397, 399, 407\*, 464, 466, 473, 474,
476, 477, 482, 483.
\:\\{store\_scaled}, \[571], 573, 575.
\:\\{str\_eq\_buf}, \[45], 259.
\:\\{str\_eq\_str}, \[46], 1260.
\:\\{str\_number}, \[38], 39, 43, 45, 46, 47, 62, 63, 79, 93, 94, 95, 177, 178,
264, 284, 407\*, 512, 519\*, 525\*, 527, 529, 530\*, 532, 549, 560, 926, 929,
934, 1257, 1279, 1299, 1355, 1377\*.
\:\\{str\_pool}, 38, \[39], 42, 43, 45, 46, 47, 59, 60, 69, 70, 256, 264, 303,
407\*, 464, 519\*, 530\*, 602, 603, 617, 638, 764, 766, 929, 931, 934, 941,
1309, 1310, 1333\*, 1334, 1368.
\:\\{str\_ptr}, 38, \[39], 41, 43, 44, 47, 59, 60, 70, 84\*, 262, 464, 517\*,
525\*, 537, 617, 642\*, 1309, 1310, 1323, 1325, 1327, 1332, 1334, 1368.
\:\\{str\_room}, \[42], 180, 260, 464, 516\*, 525\*, 939, 1257, 1279, 1328,
1333\*, 1368.
\:\\{str\_start}, 38, \[39], 40, 41, 43, 44, 45, 46, 47, 59, 60, 69, 70, 84\*,
256, 264, 407\*, 464, 517\*, 519\*, 530\*, 603, 617, 642\*, 765, 929, 931, 934,
941, 1309, 1310, 1333\*, 1368.
\:\\{str\_toks}, \[464], 465, 470.
\:\\{stretch}, \[150], 151, 164, 178, 431, 462, 625, 634, 656, 671, 716, 809,
827, 838, 869, 976, 1004, 1009, 1042, 1044, 1148, 1229, 1239, 1240.
\:\\{stretch\_order}, \[150], 164, 178, 462, 625, 634, 656, 671, 716, 809, 827,
838, 869, 976, 1004, 1009, 1148, 1239.
\:\\{stretching}, \[135], 625, 634, 658, 673, 809, 810, 811, 1148.
\:\\{string}, 37\*.
\:{string pool}, 47, 1308.
\:\9{string\_}{\.{\\string} primitive}, \[468].
\:\\{string\_code}, \[468], 469, 471, 472.
\:\\{string\_vacancies}, \[11\*], 52.
\:\\{style}, \[726], 760, 761, \[762].
\:\\{style\_node}, 160, \[688], 690, 698, 730, 731, 761, 1169.
\:\\{style\_node\_size}, \[688], 689, 698, 763.
\:\\{sub\_box}, \[681], 687, 692, 698, 720, 734, 735, 737, 738, 749, 754, 1076,
1093, 1168.
\:\\{sub\_drop}, \[700], 756.
\:\\{sub\_mark}, \[207], 294, 298, 347, 1046\*, 1175.
\:\\{sub\_mlist}, \[681], 683, 692, 720, 742, 754, 1181, 1185, 1186, 1191.
\:\\{sub\_style}, \[702], 750, 757, 759.
\:\\{sub\_sup}, 1175, \[1176].
\:\\{subscr}, \[681], 683, 686, 687, 690, 696, 698, 738, 742, 749, 750, 751,
752, 753, 754, 755, 756, 757, 759, 1151, 1163, 1165, 1175, 1176, 1177, 1186.
\:{subscripts}, 754, 1175.
\:\\{subtype}, \[133], 134\*, 135, 136, 139, 140, 144, 145, 146, 147, 149, 150,
152, 153, 154, 155, 156, 158, 159, 188, 189, 190, 191, 192, 424, 489, 495, 496,
625, 627, 634, 636, 649, 656, 668, 671, 681, 682, 686, 688, 689, 690, 696, 717,
730, 731, 732, 733, 749, 763, 766, 768, 786, 795, 809, 819, 820, 822, 837, 842%
\*, 843, 844, 866, 879, 881, 896\*, 897, 899\*, 981, 986, 988, 1008, 1009,
1018, 1020, 1021, 1060, 1061, 1078, 1100, 1101, 1113, 1125\*, 1148, 1159, 1163,
1165, 1171, 1181, 1335\*, 1341, 1349, 1356, 1357, 1358, 1373, 1374.
\:\\{sub1}, \[700], 757.
\:\\{sub2}, \[700], 759.
\:\\{succumb}, \[93], 94, 95, 1304.
\:\\{sup\_drop}, \[700], 756.
\:\\{sup\_mark}, \[207], 294, 298, 344, 355, 1046\*, 1175, 1176, 1177.
\:\\{sup\_style}, \[702], 750, 758.
\:{superscripts}, 754, 1175.
\:\\{supscr}, \[681], 683, 686, 687, 690, 696, 698, 738, 742, 750, 751, 752,
753, 754, 756, 758, 1151, 1163, 1165, 1175, 1176, 1177, 1186.
\:\\{sup1}, \[700], 758.
\:\\{sup2}, \[700], 758.
\:\\{sup3}, \[700], 758.
\:\\{sw}, \[560], 571, 575.
\:\\{switch}, \[341\*], 343, 344, 346, 350.
\:\\{synch\_h}, \[616], 620\*, 624, 628, 633, 637, 1368.
\:\\{synch\_v}, \[616], 620\*, 624, 628, 632, 633, 637, 1368.
\:{system dependencies}, 2\*, \[3], 4, 9\*, 10, 11\*, 12\*, 19, 21, 23\*, 26,
27\*, 28, 30\*, 31\*, 32\*, 33\*, 34\*, 37\*, 49\*, 56, 59, 72, 81, 84\*, 96,
109, 110\*, 112\*, 113, 161, 186, 241\*, 304\*, 313\*, 328\*, 485\*, 511, 512,
513\*, 514\*, 515, 516\*, 517\*, 518\*, 519\*, 520\*, 521\*, 523\*, 525\*, 538%
\*, 564, 591, 595\*, 597\*, 1331, 1332, 1333\*, 1338, 1340, 1376\*.
\:\\{s1}, \[82], 88.
\:\\{s2}, \[82], 88.
\:\\{s3}, \[82], 88.
\:\\{s4}, \[82], 88.
\:\|{t}, \[46], \[107], \[108], \[125], \[218], \[241\*], \[277], \[279], %
\[280], \[281], \[323], \[341\*], \[366\*], \[389], \[464], \[473], \[704], %
\[705], \[726], \[756], \[800], \[830], \[877], \[934], \[970], \[1030], %
\[1123], \[1176], \[1191], \[1198], \[1257], \[1288].
\:\\{t\_open\_in}, \[33\*], 37\*.
\:\\{t\_open\_out}, \[33\*], 1332.
\:\\{tab\_mark}, \[207], 289, 294, 342, 347, 780, 781, 782, 783, 784, 788, 1126.
\:\\{tab\_skip}, \[224].
\:\9{tab\_skip\_}{\.{\\tabskip} primitive}, \[226].
\:\\{tab\_skip\_code}, \[224], 225, 226, 778, 782, 786, 795, 809.
\:\\{tab\_token}, \[289], 1128.
\:\\{tag}, \[543], 544, 554.
\:\\{tail}, 212, \[213], 214, 215, 216, 424, 679, 718, 776, 786, 795, 796, 799,
812, 816, 888, 890, 995, 1017, 1023, 1026, 1033, 1035, 1039, 1041, 1043, 1054,
1060, 1061, 1076, 1078, 1080, 1081, 1091, 1096, 1100, 1101, 1105, 1110, 1113,
1117, 1119, 1120, 1122\*, 1123, 1125\*, 1145, 1150, 1155, 1158, 1159, 1163,
1165, 1168, 1171, 1174, 1176, 1177, 1181, 1184, 1186, 1187, 1191, 1196, 1204,
1206, 1349, 1350, 1351, 1352, 1353, 1354, 1375.
\:\\{tail\_append}, \[214], 786, 795, 816, 1038, 1039, 1054, 1056, 1060, 1061,
1091, 1093, 1100, 1103, 1112, 1113, 1117, 1125\*, 1150, 1158, 1163, 1165, 1168,
1171, 1172, 1177, 1191, 1196, 1203, 1205, 1206.
\:\\{tail\_field}, \[212], 213, 995.
\:\\{tally}, \[54], 55, 57, 58, 292, 312, 315, 316, 317.
\:\&{tats}, \[7\*].
\:\\{temp\_head}, \[162], 306, 391, 396, 400, 464, 466, 467, 470, 478, 719,
720, 754, 760, 816, 862, 863, 864, 877, 879, 880, 881, 887, 968, 1064, 1065,
1194, 1196, 1199, 1297.
\:\\{temp\_ptr}, \[115], 154, 485\*, 538\*, 618, 619, 623, 628, 629, 632, 637,
640, 679, 692, 693, 969, 1001, 1021.
\:\\{term\_and\_log}, \[54], 57, 58, 71\*, 75, 84\*, 92, 245, 534, 1298, 1328,
1335\*, 1370.
\:\\{term\_in}, \[32\*], 33\*, 34\*, 36, 37\*, 71\*, 363\*, 1338, 1339.
\:\\{term\_input}, \[71\*], 78.
\:\\{term\_offset}, \[54], 55, 57, 58, 61, 62, 71\*, 537, 638, 1280.
\:\\{term\_only}, \[54], 55, 57, 58, 71\*, 75, 92, 1298, 1333\*, 1335\*.
\:\\{term\_out}, \[32\*], 34\*, 36, 37\*, 51, 56, 1333\*.
\:\\{terminal\_input}, \[304\*], 313\*, 328\*, 330, 360.
\:\\{TEX}, \[4].
\:\.{TeX capacity exceeded ...}, 94.
\:\9{TeX capacity exceeded buffer size}{\quad buffer size}, 31\*, 328\*, 374.
\:\9{TeX capacity exceeded exception dictionary}{\quad exception dictionary},
940.
\:\9{TeX capacity exceeded font memory}{\quad font memory}, 580.
\:\9{TeX capacity exceeded grouping levels}{\quad grouping levels}, 274.
\:\9{TeX capacity exceeded hash size}{\quad hash size}, 260.
\:\9{TeX capacity exceeded input stack size}{\quad input stack size}, 321.
\:\9{TeX capacity exceeded main memory size}{\quad main memory size}, 120, 125.
\:\9{TeX capacity exceeded number of strings}{\quad number of strings}, 43, 517%
\*.
\:\9{TeX capacity exceeded parameter stack size}{\quad parameter stack size},
390.
\:\9{TeX capacity exceeded pattern memory}{\quad pattern memory}, 954, 964.
\:\9{TeX capacity exceeded pool size}{\quad pool size}, 42.
\:\9{TeX capacity exceeded save size}{\quad save size}, 273.
\:\9{TeX capacity exceeded semantic nest size}{\quad semantic nest size}, 216.
\:\9{TeX capacity exceeded text input levels}{\quad text input levels}, 328\*.
\:\.{TEX.POOL check sum...}, 53.
\:\.{TEX.POOL doesn't match}, 53.
\:\.{TEX.POOL has no check sum}, 52.
\:\.{TEX.POOL line doesn't...}, 52.
\:\\{TEX\_area}, \[514\*], 537.
\:\\{TEX\_font\_area}, \[514\*], 563.
\:\\{TEX\_format\_default}, \[520\*], 521\*, 523\*.
\:\9{TeXbook}{\sl The \TeX book}, 1, 23\*, 108, 207, 415, 446, 456, 459, 683,
688, 764, 1215, 1331.
\:\.{texput}, 35, 534, 1257.
\:\\{text}, 234, \[256], 257, 258, 259, 260, 262, 263, 264, 265\*, 491, 553,
780, 1188, 1216, 1257, 1318, 1369.
\:\.{Text line contains...}, 346.
\:\\{text\_char}, \[19], 20, 25, 30\*, 47.
\:\9{text\_font\_}{\.{\\textfont} primitive}, \[1230].
\:\\{text\_mlist}, \[689], 695, 698, 731, 1174.
\:\\{text\_size}, \[699], 703, 732, 762, 1195, 1199.
\:\\{text\_style}, \[688], 694, 703, 731, 737, 744, 745, 746, 748, 749, 758,
762, 1169, 1194, 1196.
\:\9{text\_style\_}{\.{\\textstyle} primitive}, \[1169].
\:\9{TeX82}{\TeX82}, \[1], 99.
\:\9{TFM files}{\.{TFM} files}, 539.
\:\\{tfm\_file}, \[539], 560, 563, 564, 575.
\:\.{TFtoPL}, 561.
\:\.{That makes 100 errors...}, 82.
\:\\{the}, \[210], 265\*, 266\*, 366\*, 367, 478.
\:\.{The following...deleted}, 641, 992, 1121.
\:\9{the\_}{\.{\\the} primitive}, \[265\*].
\:\\{the\_toks}, \[465], 466, 467, 478, 1297.
\:\\{thick\_mu\_skip}, \[224].
\:\9{thick\_mu\_skip\_}{\.{\\thickmuskip} primitive}, \[226].
\:\\{thick\_mu\_skip\_code}, \[224], 225, 226, 766.
\:\\{thickness}, \[683], 697, 725, 743, 744, 746, 747, 1182.
\:\\{thin\_mu\_skip}, \[224].
\:\9{thin\_mu\_skip\_}{\.{\\thinmuskip} primitive}, \[226].
\:\\{thin\_mu\_skip\_code}, \[224], 225, 226, 229, 766.
\:\.{This can't happen}, 95.
\:\9{this can't happen align}{\quad align}, 800.
\:\9{this can't happen copying}{\quad copying}, 206.
\:\9{this can't happen curlevel}{\quad curlevel}, 281.
\:\9{this can't happen disc1}{\quad disc1}, 841\*.
\:\9{this can't happen disc2}{\quad disc2}, 842\*.
\:\9{this can't happen disc3}{\quad disc3}, 871\*.
\:\9{this can't happen display}{\quad display}, 1200.
\:\9{this can't happen endgroup}{\quad endgroup}, 1335\*.
\:\9{this can't happen endv}{\quad endv}, 791.
\:\9{this can't happen ext1}{\quad ext1}, 1348.
\:\9{this can't happen ext2}{\quad ext2}, 1357.
\:\9{this can't happen ext3}{\quad ext3}, 1358.
\:\9{this can't happen ext4}{\quad ext4}, 1373.
\:\9{this can't happen flushing}{\quad flushing}, 202.
\:\9{this can't happen if}{\quad if}, 497.
\:\9{this can't happen line breaking}{\quad line breaking}, 877.
\:\9{this can't happen mlist1}{\quad mlist1}, 728.
\:\9{this can't happen mlist2}{\quad mlist2}, 754.
\:\9{this can't happen mlist3}{\quad mlist3}, 761.
\:\9{this can't happen mlist4}{\quad mlist4}, 766.
\:\9{this can't happen page}{\quad page}, 1000.
\:\9{this can't happen paragraph}{\quad paragraph}, 866.
\:\9{this can't happen prefix}{\quad prefix}, 1211.
\:\9{this can't happen pruning}{\quad pruning}, 968.
\:\9{this can't happen right}{\quad right}, 1185.
\:\9{this can't happen rightbrace}{\quad rightbrace}, 1068\*.
\:\9{this can't happen vcenter}{\quad vcenter}, 736.
\:\9{this can't happen vertbreak}{\quad vertbreak}, 973.
\:\9{this can't happen vlistout}{\quad vlistout}, 630.
\:\9{this can't happen vpack}{\quad vpack}, 669.
\:\9{this can't happen 256 spans}{\quad 256 spans}, 798.
\:\\{this\_box}, \[619], 624, 625, \[629], 633, 634.
\:\\{this\_if}, \[498], 501, 503, 505, 506.
\:\\{threshold}, \[828], 851, 854, 863.
\:\.{Tight \\hbox...}, 667.
\:\.{Tight \\vbox...}, 678.
\:\\{tight\_fit}, \[817], 819, 830, 833, 834, 836, 853.
\:\\{time}, \[236], 241\*, 536, 617.
\:\9{time\_}{\.{\\time} primitive}, \[238].
\:\\{time\_code}, \[236], 237, 238.
\:\&{tini}, \[8\*].
\:\\{tmp\_cor\_buf}, \[37\*].
\:\\{tmp\_in}, \[37\*].
\:\.{to}, 645, 1082.
\:\\{tok\_val}, \[410], 415, 418, 428, 465.
\:{token}, 289.
\:\\{token\_list}, \[307], 311, 312, 323, 325, 330, 337, 341\*, 346, 390.
\:\\{token\_ref\_count}, \[200], 203, 291, 473, 482, 979.
\:\\{token\_show}, \[295], 296, 323, 401, 1279, 1284, 1297.
\:\\{token\_type}, \[307], 311, 312, 314, 319, 323, 324, 325, 327, 379, 1095.
\:\\{toks}, \[230].
\:\9{toks\_}{\.{\\toks} primitive}, \[265\*].
\:\\{toks\_base}, \[230], 231, 232\*, 233, 415, 1224, 1226, 1227.
\:\9{toks\_def\_}{\.{\\toksdef} primitive}, \[1222].
\:\\{toks\_def\_code}, \[1222], 1224.
\:\\{toks\_register}, \[209\*], 265\*, 266\*, 413, 415, 1210, 1226, 1227.
\:\\{tolerance}, \[236], 240, 828, 863.
\:\9{tolerance\_}{\.{\\tolerance} primitive}, \[238].
\:\\{tolerance\_code}, \[236], 237, 238.
\:\.{Too many \}'s}, 1068\*.
\:\\{too\_small}, \[1303], 1306.
\:\\{top}, \[546].
\:\\{top\_bot\_mark}, \[210], 296, 366\*, 367, 384, 385, 386.
\:\\{top\_edge}, \[629], 636.
\:\\{top\_mark}, \[382], 383, 1012.
\:\9{top\_mark\_}{\.{\\topmark} primitive}, \[384].
\:\\{top\_mark\_code}, \[382], 384, 386.
\:\\{top\_skip}, \[224].
\:\9{top\_skip\_}{\.{\\topskip} primitive}, \[226].
\:\\{top\_skip\_code}, \[224], 225, 226, 1001.
\:\\{total\_demerits}, \[819], 845, 846, 855, 864, 874, 875.
\:\9{total\_height}{\.{total height}}, 986.
\:\\{total\_mathex\_params}, \[701], 1195.
\:\\{total\_mathsy\_params}, \[700], 1195.
\:\\{total\_pages}, \[592], 593, 617, 640, 642\*.
\:\\{total\_shrink}, \[646], 650, 656, 664, 665, 666, 667, 671, 676, 677, 678,
796, 1201.
\:\\{total\_stretch}, \[646], 650, 656, 658, 659, 660, 671, 673, 674, 796.
\:\\{trace\_depth}, 341\*, 366\*, 407\*, 440\*, 448\*, \[1379\*], 1380\*.
\:\\{tracing\_commands}, \[236], 367, 498, 509, 1031.
\:\9{tracing\_commands\_}{\.{\\tracingcommands} primitive}, \[238].
\:\\{tracing\_commands\_code}, \[236], 237, 238.
\:\\{tracing\_lost\_chars}, \[236], 581.
\:\9{tracing\_lost\_chars\_}{\.{\\tracinglostchars} primitive}, \[238].
\:\\{tracing\_lost\_chars\_code}, \[236], 237, 238.
\:\\{tracing\_macros}, \[236], 323, 389, 400.
\:\9{tracing\_macros\_}{\.{\\tracingmacros} primitive}, \[238].
\:\\{tracing\_macros\_code}, \[236], 237, 238.
\:\\{tracing\_online}, \[236], 245, 1293, 1298.
\:\9{tracing\_online\_}{\.{\\tracingonline} primitive}, \[238].
\:\\{tracing\_online\_code}, \[236], 237, 238.
\:\\{tracing\_output}, \[236], 638, 641.
\:\9{tracing\_output\_}{\.{\\tracingoutput} primitive}, \[238].
\:\\{tracing\_output\_code}, \[236], 237, 238.
\:\\{tracing\_pages}, 7\*, \[236], 987, 1005, 1010.
\:\9{tracing\_pages\_}{\.{\\tracingpages} primitive}, \[238].
\:\\{tracing\_pages\_code}, \[236], 237, 238.
\:\\{tracing\_paragraphs}, 7\*, \[236], 845, 855, 863.
\:\9{tracing\_paragraphs\_}{\.{\\tracingparagraphs} primitive}, \[238].
\:\\{tracing\_paragraphs\_code}, \[236], 237, 238.
\:\\{tracing\_restores}, \[236], 283.
\:\9{tracing\_restores\_}{\.{\\tracingrestores} primitive}, \[238].
\:\\{tracing\_restores\_code}, \[236], 237, 238.
\:\\{tracing\_stats}, 117, \[236], 341\*, 366\*, 407\*, 440\*, 448\*, 639,
1326, 1333\*.
\:\9{tracing\_stats\_}{\.{\\tracingstats} primitive}, \[238].
\:\\{tracing\_stats\_code}, \[236], 237, 238.
\:\.{Transcript written...}, 1333\*.
\:\\{trap\_zero\_glue}, 1228, \[1229], 1236.
\:\\{trick\_buf}, \[54], 58, 315, 317.
\:\\{trick\_count}, \[54], 58, 315, 316, 317.
\:{Trickey, Howard Wellington}, 2\*.
\:\\{trie}, 920, \[921], 922, 950, 951, 952, 953, 954, 958, 959, 960, 966,
1324, 1325.
\:\\{trie\_back}, \[950], 951, 954, 956.
\:\\{trie\_c}, \[945], 947, 949, 953, 955, 956, 959, 963, 964.
\:\\{trie\_char}, 920, \[921], 923, 952, 959, 966.
\:\\{trie\_fix}, 958, \[959].
\:\\{trie\_hash}, \[946], 947, 948, 949, 950.
\:\\{trie\_l}, \[945], 947, 948, 957, 959, 960, 963, 964.
\:\\{trie\_link}, 920, \[921], 923, 950, 951, 952, 953, 954, 955, 956, 959, 966.
\:\\{trie\_max}, \[950], 951, 952, 954, 958, 960, 966, 1324, 1325.
\:\\{trie\_min}, \[950], 951, 953.
\:\\{trie\_node}, \[947], 948.
\:\\{trie\_o}, \[945], 947, 959, 963, 964.
\:\\{trie\_op}, 920, \[921], 923, 924, 943, 952, 959, 966.
\:\\{trie\_op\_hash}, \[943], 944, 946, 949.
\:\\{trie\_op\_hash\_size}, \[943], 944, 949.
\:\\{trie\_op\_ptr}, \[943], 944, 949, 952, 960, 1324, 1325.
\:\\{trie\_pack}, \[957], 966.
\:\\{trie\_pointer}, \[920], 921, 922, 945, 946, 947, 948, 949, 950, 951, 953,
957, 959, 960.
\:\\{trie\_ptr}, \[945], 949, 951, 964.
\:\\{trie\_r}, \[945], 947, 948, 955, 956, 957, 959, 963, 964.
\:\\{trie\_ref}, \[950], 951, 953, 956, 957, 958, 959.
\:\\{trie\_root}, \[945], 948, 949, 958, 960, 966.
\:\\{trie\_size}, \[11\*], 920, 947, 949, 954, 964, 1325.
\:\\{trie\_taken}, \[950], 951, 953, 954, 956, 958.
\:\\{true}, 4, 16, 31\*, 33\*, 34\*, 37\*, 45, 46, 49\*, 51, 53, 71\*, 77, 88,
97, 98, 104, 105, 106, 107, 168, 169, 256, 257, 259, 327, 328\*, 336\*, 346,
361, 362, 363\*, 365, 374, 378, 407\*, 413, 430, 440\*, 444, 447, 453, 461,
462, 486, 501, 512, 516\*, 524, 526, 563, 578, 592, 621, 628, 637, 638, 641,
663\*, 675\*, 706, 719, 791, 827, 828, 829, 851, 854, 863, 880, 882, 956, 962,
963, 992, 1020, 1021, 1025, 1040, 1051, 1054, 1090\*, 1101, 1121, 1163, 1194,
1195, 1218, 1253, 1258, 1279, 1283, 1298, 1303, 1336, 1342, 1354, 1371, 1374.
\:\.{true}, 453.
\:\\{try\_break}, 828, \[829], 839, 851, 858, 862, 866, 868, 870, 873, 879.
\:\\{TTY}, 32\*, 33\*.
\:\\{two}, \[101], 102.
\:\\{two\_choices}, \[113].
\:\\{two\_halves}, \[113], 118, 124, 172, 221, 256, 684, 921, 960.
\:\\{type}, \[4], \[133], 134\*, 135, 136, 137, 138, 139, 140, 141, 142, 143,
144, 145, 146, 147, 148, 149, 150, 152, 153, 155, 156, 157, 158, 159, 160, 175,
183\*, 184, 202, 206, 424, 489, 495, 496, 497, 505, 622, 623, 626, 628, 631,
632, 635, 637, 640, 649, 651, 653, 655, 668, 669, 670, 680, 681, 682, 683, 686,
687, 688, 689, 696, 698, 713, 715, 720, 721, 726, 727, 728, 729, 731, 732, 736,
747, 750, 752, 761, 762, 767, 768, 796, 799, 801, 805, 807, 809, 810, 811, 816,
819, 820, 822, 830, 832, 837, 841\*, 842\*, 843, 844, 845, 856, 858, 859, 860,
861, 862, 864, 865, 866, 871\*, 874, 875, 879, 881, 896\*, 897, 899\*, 914,
968, 970, 972, 973, 976, 978, 979, 981, 986, 988, 993, 996, 997, 1000, 1004,
1008, 1009, 1010, 1011, 1013, 1014, 1021, 1074, 1080, 1081, 1087, 1100, 1101,
1105, 1110, 1113, 1121, 1147\*, 1155, 1158, 1159, 1163, 1165, 1168, 1181, 1185,
1186, 1191, 1202, 1203, 1341, 1349.
\:\.{Type <return> to proceed...}, 85.
\:\|{u}, \[69], \[107], \[389], \[560], \[706], \[791], \[800], \[929], \[934],
\[944], \[1257].
\:\\{u\_part}, 768, \[769], 779, 788, 794, 801.
\:\\{u\_template}, \[307], 314, 324, 788.
\:\\{uc\_code}, \[230], 232\*, 407\*.
\:\9{uc\_code\_}{\.{\\uccode} primitive}, \[1230].
\:\\{uc\_code\_base}, \[230], 235, 1230, 1231, 1286, 1288.
\:\\{uc\_hyph}, \[236], 891, 896\*.
\:\9{uc\_hyph\_}{\.{\\uchyph} primitive}, \[238].
\:\\{uc\_hyph\_code}, \[236], 237, 238.
\:\\{un\_hbox}, \[208\*], 1090\*, 1107, 1108, 1109.
\:\9{un\_hbox\_}{\.{\\unhbox} primitive}, \[1107].
\:\9{un\_hcopy\_}{\.{\\unhcopy} primitive}, \[1107].
\:\9{un\_kern\_}{\.{\\unkern} primitive}, \[1107].
\:\9{un\_penalty\_}{\.{\\unpenalty} primitive}, \[1107].
\:\9{un\_skip\_}{\.{\\unskip} primitive}, \[1107].
\:\\{un\_vbox}, \[208\*], 1046\*, 1094, 1107, 1108, 1109.
\:\9{un\_vbox\_}{\.{\\unvbox} primitive}, \[1107].
\:\9{un\_vcopy\_}{\.{\\unvcopy} primitive}, \[1107].
\:\\{unbalance}, \[389], 391, 396, 399, \[473], 477.
\:\.{Unbalanced output routine}, 1027.
\:\.{Unbalanced write...}, 1372.
\:\.{Undefined control sequence}, 370.
\:\\{undefined\_control\_sequence}, \[222], 232\*, 256, 257, 259, 262, 268,
282, 290, 1318, 1319.
\:\\{undefined\_cs}, \[210], 222, 366\*, 372, 1226, 1227, 1295.
\:\\{under\_noad}, \[687], 690, 696, 698, 733, 761, 1156, 1157.
\:\.{Underfull \\hbox...}, 660.
\:\.{Underfull \\vbox...}, 674.
\:\9{underline\_}{\.{\\underline} primitive}, \[1156].
\:\\{undump}, \[1306], 1310, 1312, 1314, 1319, 1323, 1325, 1327.
\:\\{undump\_end}, \[1306].
\:\\{undump\_end\_end}, \[1306].
\:\\{undump\_four\_ASCII}, \[1310].
\:\\{undump\_hh}, \[1306], 1319, 1325.
\:\\{undump\_int}, \[1306], 1308, 1312, 1317, 1319, 1323, 1327.
\:\\{undump\_qqqq}, \[1306], 1310, 1323.
\:\\{undump\_size}, \[1306], 1310, 1321, 1325.
\:\\{undump\_size\_end}, \[1306].
\:\\{undump\_size\_end\_end}, \[1306].
\:\\{undump\_wd}, \[1306], 1312, 1317, 1321.
\:\\{unfloat}, \[109], 658, 664, 673, 676, 810, 811.
\:\\{unhyphenated}, \[819], 829, 837, 864, 866, 868.
\:\\{unity}, \[101], 103, 114, 164, 186, 453, 568, 1259.
\:\\{unpackage}, 1109, \[1110].
\:\\{unsave}, \[281], 283, 791, 800, 1026, 1063\*, 1068\*, 1086, 1100, 1119,
1133, 1168, 1174, 1186, 1191, 1194, 1196, 1200, 1335\*.
\:\\{unset\_node}, 136, \[159], 175, 183\*, 184, 202, 206, 651, 669, 682, 688,
689, 768, 796, 799, 801, 805.
\:\\{update\_active}, \[861].
\:\\{update\_heights}, \[970], 972, 973, 994, 997, 1000.
\:\\{update\_terminal}, \[34\*], 37\*, 61, 71\*, 86, 362, 524, 537, 638, 1280,
1338.
\:\\{update\_width}, \[832], 860.
\:\9{uppercase\_}{\.{\\uppercase} primitive}, \[1286].
\:\.{Use of x doesn't match...}, 398.
\:\\{use\_err\_help}, \[79], 80, 89, 90, 1283.
\:\|{v}, \[69], \[107], \[389], \[450], \[706], \[715], \[736], \[743], \[749],
\[800], \[830], \[922], \[934], \[944], \[960], \[977], \[1138].
\:\\{v\_offset}, \[247], 640, 641.
\:\9{v\_offset\_}{\.{\\voffset} primitive}, \[248].
\:\\{v\_offset\_code}, \[247], 248.
\:\\{v\_part}, 768, \[769], 779, 789, 794, 801.
\:\\{v\_template}, \[307], 314, 789.
\:\\{vacuous}, \[440\*], 444, 445.
\:\\{vadjust}, \[208\*], 265\*, 266\*, 1097, 1098, 1099, 1100.
\:\9{vadjust\_}{\.{\\vadjust} primitive}, \[265\*].
\:\\{valign}, \[208\*], 265\*, 266\*, 1046\*, 1090\*, 1130.
\:\9{valign\_}{\.{\\valign} primitive}, \[265\*].
\:\\{var\_code}, \[232\*], 1151, 1155, 1165.
\:\\{var\_delimiter}, \[706], 737, 748, 762.
\:\\{var\_used}, \[117], 125, 130, 164, 639, 1311, 1312.
\:\\{vbadness}, \[236], 673, 674, 676, 677, 678, 1012, 1017.
\:\9{vbadness\_}{\.{\\vbadness} primitive}, \[238].
\:\\{vbadness\_code}, \[236], 237, 238.
\:\9{vbox\_}{\.{\\vbox} primitive}, \[1071].
\:\\{vbox\_group}, \[269], 1083, 1085.
\:\\{vcenter}, \[208\*], 265\*, 266\*, 1046\*, 1167.
\:\9{vcenter\_}{\.{\\vcenter} primitive}, \[265\*].
\:\\{vcenter\_group}, \[269], 1167, 1168.
\:\\{vcenter\_noad}, \[687], 690, 696, 698, 733, 761, 1168.
\:\\{vert\_break}, \[970], 971, 976, 977, 980, 982, 1010.
\:\\{very\_loose\_fit}, \[817], 819, 830, 833, 834, 836, 852.
\:\9{vfil\_}{\.{\\vfil} primitive}, \[1058].
\:\9{vfil\_neg\_}{\.{\\vfilneg} primitive}, \[1058].
\:\9{vfill\_}{\.{\\vfill} primitive}, \[1058].
\:\\{vfuzz}, \[247], 677, 1012, 1017.
\:\9{vfuzz\_}{\.{\\vfuzz} primitive}, \[248].
\:\\{vfuzz\_code}, \[247], 248.
\:\.{VIRTEX}, 1331.
\:{virtual memory}, 126.
\:{Vitter, Jeffrey Scott}, 261.
\:\\{vlist\_node}, \[137], 148, 159, 175, 183\*, 184, 202, 206, 505, 618, 622,
623, 628, 629, 631, 632, 637, 640, 644, 651, 668, 669, 681, 713, 715, 720, 736,
747, 750, 807, 809, 811, 841\*, 842\*, 866, 871\*, 968, 973, 978, 1000, 1074,
1080, 1087, 1110, 1147\*.
\:\\{vlist\_out}, 592, 615, 616, 618, 619, 623, 628, \[629], 632, 637, 638,
640, 693, 1373.
\:\\{vmode}, \[211], 215, 416, 417, 418, 422, 424, 501, 775, 785, 786, 804,
807, 808, 809, 812, 1025, 1029, 1045, 1046\*, 1048, 1056, 1057, 1071, 1072,
1073, 1076, 1078, 1079, 1080, 1083, 1090\*, 1091, 1094, 1098, 1099, 1103, 1105,
1109, 1110, 1111, 1130, 1167, 1243, 1244.
\:\\{vmove}, \[208\*], 1048, 1071, 1072, 1073.
\:\\{vpack}, 236, 644, 645, 646, \[668], 705, 735, 738, 759, 799, 804, 977,
1021, 1100, 1168.
\:\\{vpackage}, \[668], 796, 977, 1017, 1086.
\:\\{vrule}, \[208\*], 265\*, 266\*, 463, 1056, 1084, 1090\*.
\:\9{vrule\_}{\.{\\vrule} primitive}, \[265\*].
\:\\{vsize}, \[247], 980, 987.
\:\9{vsize\_}{\.{\\vsize} primitive}, \[248].
\:\\{vsize\_code}, \[247], 248.
\:\\{vskip}, \[208\*], 1046\*, 1057, 1058, 1059, 1078, 1094.
\:\9{vskip\_}{\.{\\vskip} primitive}, \[1058].
\:\\{vsplit}, 967, \[977], 978, 980, 1082.
\:\9{vsplit\_}{\.{\\vsplit needs a \\vbox}}, 978.
\:\9{vsplit\_}{\.{\\vsplit} primitive}, \[1071].
\:\\{vsplit\_code}, \[1071], 1072, 1079.
\:\9{vss\_}{\.{\\vss} primitive}, \[1058].
\:\9{vtop\_}{\.{\\vtop} primitive}, \[1071].
\:\\{vtop\_code}, \[1071], 1072, 1083, 1085, 1086.
\:\\{vtop\_group}, \[269], 1083, 1085.
\:\|{w}, \[114], \[147], \[156], \[275], \[278], \[279], \[607], \[649], %
\[668], \[706], \[715], \[738], \[791], \[800], \[906], \[994], \[1123], %
\[1138], \[1198], \[1302], \[1303], \[1349], \[1350].
\:\\{w\_close}, \[28], 1329, 1337.
\:\\{w\_make\_name\_string}, \[525\*], 1328.
\:\\{w\_open\_in}, \[27\*], 524.
\:\\{w\_open\_out}, \[27\*], 1328.
\:\\{wait}, \[1012], 1020, 1021, 1022.
\:\\{wake\_up\_terminal}, \[34\*], 37\*, 51, 71\*, 73, 363\*, 484, 524, 530\*,
1294, 1297, 1303, 1333\*, 1338.
\:\\{warning\_index}, \[305], 331, 338, 389, 390, 395, 396, 398, 401, 473, 479,
482, 774, 777.
\:\\{warning\_issued}, \[76], 245, 1335\*.
\:\\{was\_free}, \[165], 167, 171.
\:\\{was\_hi\_min}, \[165], 166, 167, 171.
\:\\{was\_lo\_max}, \[165], 166, 167, 171.
\:\\{was\_mem\_end}, \[165], 166, 167, 171.
\:\9{wd\_}{\.{\\wd} primitive}, \[416].
\:\.{WEB}, 1, 4, 38, 40, 50, 1308.
\:\\{whatsit\_node}, \[146], 148, 175, 183\*, 202, 206, 622, 631, 651, 669,
730, 761, 866, 896\*, 899\*, 968, 973, 1000, 1147\*, 1341, 1349.
\:\\{widow\_penalty}, \[236], 1096.
\:\9{widow\_penalty\_}{\.{\\widowpenalty} primitive}, \[238].
\:\\{widow\_penalty\_code}, \[236], 237, 238.
\:\.{width}, 463.
\:\\{width}, \[135], 136, 138, 139, 147, 150, 151, 155, 156, 178, 184, 187,
191, 192, 424, 429, 431, 451, 462, 463, 554, 605, 607, 611, 622, 623, 625, 626,
631, 633, 634, 635, 641, 651, 653, 656, 657, 666, 668, 669, 670, 671, 679, 683,
688, 706, 709, 714, 715, 716, 717, 731, 738, 744, 747, 749, 750, 757, 758, 759,
768, 779, 793, 796, 797, 798, 801, 802, 803, 804, 806, 807, 808, 809, 810, 811,
827, 837, 838, 841\*, 842\*, 866, 869, 871\*, 881, 969, 976, 996, 1001, 1004,
1009, 1042, 1044, 1054, 1091, 1093, 1147\*, 1148, 1199, 1201, 1205, 1229, 1239,
1240.
\:\\{width\_base}, \[550], 552, 554, 566, 569, 571, 576, 1322, 1323.
\:\\{width\_index}, \[543], 550.
\:\\{width\_offset}, \[135], 416, 417, 1247.
\:{Wirth, Niklaus}, 10.
\:\\{wlog}, \[56], 58, 536, 1334.
\:\\{wlog\_cr}, \[56], 57, 58, 1333\*.
\:\\{wlog\_ln}, \[56], 1334.
\:\\{word\_define}, \[1214], 1228, 1232, 1236.
\:\\{word\_file}, 25, 27\*, 28, \[113], 525\*, 1305.
\:\\{words}, \[204], 205, 206, 1357.
\:\\{write}, 37\*, 56, 58.
\:\9{write\_}{\.{\\write} primitive}, \[1344].
\:\\{write\_dvi}, \[597\*], 598, 599.
\:\\{write\_file}, 57, 58, \[1342], 1367, 1374.
\:\\{write\_ln}, 37\*, 51, 56, 57, 1333\*.
\:\\{write\_loc}, 1313, 1314, 1344, \[1345], 1371.
\:\\{write\_node}, \[1341], 1344, 1346, 1348, 1356, 1357, 1358, 1373, 1374.
\:\\{write\_node\_size}, \[1341], 1350, 1352, 1353, 1354, 1357, 1358.
\:\\{write\_open}, \[1342], 1343, 1367, 1370, 1374.
\:\\{write\_out}, \[1370], 1374.
\:\\{write\_stream}, \[1341], 1350, 1354, 1355, 1370, 1374.
\:\\{write\_text}, \[307], 314, 323, 1340, 1371.
\:\\{write\_tokens}, \[1341], 1352, 1353, 1354, 1356, 1357, 1358, 1368, 1371.
\:\\{writing}, \[578].
\:\\{wterm}, \[56], 58, 61.
\:\\{wterm\_cr}, \[56], 57, 58.
\:\\{wterm\_ln}, \[56], 61, 524, 1303, 1332.
\:{Wyatt, Douglas Kirk}, 2\*.
\:\\{w0}, 585, \[586], 604, 609.
\:\\{w1}, 585, \[586], 607.
\:\\{w2}, \[585].
\:\\{w3}, \[585].
\:\\{w4}, \[585].
\:\|{x}, \[37\*], \[100], \[105], \[106], \[107], \[587], \[600], \[649], %
\[668], \[706], \[720], \[726], \[735], \[737], \[738], \[743], \[749], \[756],
\[1123], \[1302], \[1303].
\:\\{x\_height}, 547, \[558], 559, 738, 1123.
\:\\{x\_height\_code}, \[547], 558.
\:\\{x\_leaders}, \[149], 190, 627, 1071, 1072.
\:\9{x\_leaders\_}{\.{\\xleaders} primitive}, \[1071].
\:\\{x\_over\_n}, \[106], 703, 716, 717, 986, 1008, 1009, 1010, 1240.
\:\\{x\_token}, 364, \[381], 478, 1036, 1152.
\:\9{xchar\_}{\.{\\xchar} primitive}, \[265\*].
\:\\{xchar\_num}, \[208\*], 265\*, 266\*, 1046\*, 1090\*, 1122\*, 1124\*.
\:\\{xchr}, \[20], 21, 23\*, 24, 38, 49\*, 58, 363\*, 519\*, 530\*, 1333\*.
\:\&{xclause}, 16.
\:\9{xdef\_}{\.{\\xdef} primitive}, \[1208].
\:\\{xeq\_level}, \[253], 254, 268, 278, 279, 283, 1304.
\:\\{xn\_over\_d}, \[107], 455, 457, 458, 568, 716, 1044, 1260.
\:\\{xord}, \[20], 24, 31\*, 37\*, 52, 53, 523\*, 525\*.
\:\\{xpand}, \[473], 477, 479.
\:\\{xray}, \[208\*], 1290, 1291, 1292.
\:\\{xspace\_skip}, \[224], 1043.
\:\9{xspace\_skip\_}{\.{\\xspaceskip} primitive}, \[226].
\:\\{xspace\_skip\_code}, \[224], 225, 226, 1043.
\:\\{xxx1}, 585, \[586], 1368.
\:\\{xxx2}, \[585].
\:\\{xxx3}, \[585].
\:\\{xxx4}, 585, \[586], 1368.
\:\\{x0}, 585, \[586], 604, 609.
\:\\{x1}, 585, \[586], 607.
\:\\{x2}, \[585].
\:\\{x3}, \[585].
\:\\{x4}, \[585].
\:\|{y}, \[105], \[706], \[726], \[735], \[737], \[738], \[743], \[749], \[756].
\:\\{y\_here}, \[608], 609, 611, 612, 613.
\:\\{y\_OK}, \[608], 609, 612.
\:\\{y\_seen}, \[611], 612.
\:\\{year}, \[236], 241\*, 536, 617, 1328.
\:\9{year\_}{\.{\\year} primitive}, \[238].
\:\\{year\_code}, \[236], 237, 238.
\:\.{You already have nine...}, 476.
\:\.{You can't \\insert255}, 1099.
\:\.{You can't dump...}, 1304.
\:\.{You can't use \\hrule...}, 1095.
\:\.{You can't use \\long...}, 1213.
\:\.{You can't use a prefix with x}, 1212.
\:\.{You can't use x after ...}, 428, 1237.
\:\.{You can't use x in y mode}, 1049.
\:\.{You have to increase POOLSIZE}, 52.
\:\\{you\_cant}, \[1049], 1050, 1080, 1106.
\:\\{yz\_OK}, \[608], 609, 610, 612.
\:\\{y0}, 585, \[586], 594\*, 604, 609.
\:\\{y1}, 585, \[586], 607, 613.
\:\\{y2}, \[585], 594\*.
\:\\{y3}, \[585].
\:\\{y4}, \[585].
\:\|{z}, \[560], \[706], \[726], \[743], \[749], \[756], \[922], \[927], %
\[953], \[959], \[1198].
\:\\{z\_here}, \[608], 609, 611, 612, 614.
\:\\{z\_OK}, \[608], 609, 612.
\:\\{z\_seen}, \[611], 612.
\:{Zabala Salelles, Ignacio Andres}, 2\*.
\:\\{zero\_glue}, \[162], 175, 224, 228, 424, 462, 732, 802, 887, 1041, 1042,
1043, 1171, 1229.
\:\\{zero\_token}, \[445], 452, 473, 476, 479.
\:\\{z0}, 585, \[586], 604, 609.
\:\\{z1}, 585, \[586], 607, 614.
\:\\{z2}, \[585].
\:\\{z3}, \[585].
\:\\{z4}, \[585].
\fin
\:\X445:Accumulate the constant until \\{cur\_tok} is not a suitable digit\X
\U section~444.
\:\X842\*:Add the width of node \|s to \\{break\_width} and increase \|t,
unless it's discardable\X
\U section~840.
\:\X871\*:Add the width of node \|s to \\{disc\_width}\X
\U section~870.
\:\X457:Adjust \(f)for the magnification ratio\X
\U section~453.
\:\X1214:Adjust \(f)for the setting of \.{\\globaldefs}\X
\U section~1211.
\:\X746:Adjust \(s)\\{shift\_up} and \\{shift\_down} for the case of a fraction
line\X
\U section~743.
\:\X745:Adjust \(s)\\{shift\_up} and \\{shift\_down} for the case of no
fraction line\X
\U section~743.
\:\X1034:Adjust \(t)the space factor, based on its current value and \|c\X
\U section~1033.
\:\X867\*:Advance \(c)\\{cur\_p} to the node following the present string of
characters\X
\U section~866.
\:\X1362:Advance \(p)past a whatsit node in the \\{line\_break} loop\X
\U section~866.
\:\X394:Advance \(r)\|r; \&{goto} \\{found} if the parameter delimiter has been
fully matched, otherwise \&{goto} \\{continue}\X
\U section~392.
\:\X129:Allocate entire node \|p and \&{goto} \\{found}\X
\U section~127.
\:\X128:Allocate from the top of node \|p and \&{goto} \\{found}\X
\U section~127.
\:\X1106:Apologize for inability to do the operation now, unless \.{\\unskip}
follows non-glue\X
\U section~1105.
\:\X567:Apologize for not loading the font, \&{goto} \\{done}\X
\U section~566.
\:\X1038:Append a kern, \&{goto} \\{main\_loop\_2}\X
\U section~1037.
\:\X1078:Append a new leader node that uses \\{cur\_box}\X
\U section~1075.
\:\X962:Append a new letter or a hyphen level\X
\U section~961.
\:\X937:Append a new letter or hyphen\X
\U section~935.
\:\X1041:Append a normal inter-word space to the current list, then \&{goto} %
\\{big\_switch}\X
\U section~1030.
\:\X890:Append a penalty node, if a nonzero penalty is appropriate\X
\U section~880.
\:\X1008:Append an insertion to the current page and \&{goto} \\{contribute}\X
\U section~1000.
\:\X767:Append any \\{new\_hlist} entries for \|q, and any appropriate
penalties\X
\U section~760.
\:\X1076:Append box \\{cur\_box} to the current list, shifted by $\\{saved}(0)$%
\X
\U section~1075.
\:\X1033:Append character \\{cur\_chr} and the following characters (if~any) to
the current hlist in the current font; \&{goto} \\{reswitch} when a
non-character has been fetched\X
\U section~1030.
\:\X1035:Append character \|l and the following characters (if any) to the
current hlist, in font \|f; if \\{ligature\_present}, detach a ligature node
starting at $\\{link}(\|q)$; if \|c is a hyphen, append a null \\{disc\_node};
finally \&{goto} \\{reswitch}\X
\U section~1033.
\:\X766:Append inter-element spacing based on \\{r\_type} and \|t\X
\U section~760.
\:\X809:Append tabskip glue and an empty box to list \|u, and update \|s and %
\|t as the prototype nodes are passed\X
\U section~808.
\:\X1125\*:Append the accent with appropriate kerns, then set $\|p\K\|q$\X
\U section~1123.
\:\X778:Append the current tabskip glue to the preamble list\X
\U section~777.
\:\X1204:Append the display and perhaps also the equation number\X
\U section~1199.
\:\X1205:Append the glue or equation number following the display\X
\U section~1199.
\:\X1203:Append the glue or equation number preceding the display\X
\U section~1199.
\:\X888:Append the new box to the current vertical list, followed by the list
of special nodes taken out of the box by the packager\X
\U section~880.
\:\X938:Append the value \|n to list \|p\X
\U section~937.
\:\X909:Append to the ligature and \&{goto} \\{continue}\X
\U section~908.
\:\X236:Assign the values $\\{depth\_threshold}\K\\{show\_box\_depth}$ and $%
\\{breadth\_max}\K\\{show\_box\_breadth}$\X
\U section~198.
\:\X1217, 1218, 1221, 1224, 1225, 1226, 1228, 1232, 1234, 1235, 1241, 1242,
1248, 1252, 1253, 1256, 1264:Assignments\X
\U section~1211.
\:\X911:Attach kerning, if $\|w\I0$\X
\U section~906.
\:\X1120:Attach list \|p to the current list, and record its length; then
finish up and \&{return}\X
\U section~1119.
\:\X751:Attach the limits to \|y and adjust $\\{height}(\|v)$, $\\{depth}(\|v)$
to account for their presence\X
\U section~750.
\:\X337:Back up an outer control sequence so that it can be reread\X
\U section~336\*.
\:\X57, 58, 59, 60, 62, 63, 64, 65, 262, 263, 518\*, 699, 1355:Basic printing
procedures\X
\U section~4.
\:\X1017:Break the current page at node \|p, put it in box~255, and put the
remaining nodes on the contribution list\X
\U section~1014.
\:\X876:Break the paragraph at the chosen breakpoints, justify the resulting
lines to the correct widths, and append them to the current vertical list\X
\U section~815.
\:\X907:Build a list of characters in a maximal ligature, and set \|w to the
amount of kerning that should follow\X
\U section~906.
\:\X1149:Calculate the length, \|l, and the shift amount, \|s, of the display
lines\X
\U section~1145.
\:\X1146:Calculate the natural width, \|w, by which the characters of the final
line extend to the right of the reference point, plus two ems; or set $\|w\K%
\\{max\_dimen}$ if the non-blank information on that line is affected by
stretching or shrinking\X
\U section~1145.
\:\X889:Call the packaging subroutine, setting \\{just\_box} to the justified
box\X
\U section~880.
\:\X866:Call \\{try\_break} if \\{cur\_p} is a legal breakpoint; on the second
pass, also try to hyphenate the next word, if \\{cur\_p} is a glue node; then
advance \\{cur\_p} to the next node of the paragraph that could possibly be a
legal breakpoint\X
\U section~863.
\:\X206:Case statement to copy different types and set \\{words} to the number
of initial words not yet copied\X
\U section~205.
\:\X733:Cases for noads that can follow a \\{bin\_noad}\X
\U section~728.
\:\X730:Cases for nodes that can appear in an mlist, after which we \&{goto} %
\\{done\_with\_node}\X
\U section~728.
\:\X698:Cases of \\{flush\_node\_list} that arise in mlists only\X
\U section~202.
\:\X1085, 1100, 1118, 1132, 1133, 1168, 1173, 1186:Cases of \\{handle\_right%
\_brace} where a \\{right\_brace} triggers a delayed action\X
\U section~1068\*.
\:\X1347:Cases of \\{main\_control} that are for extensions to \TeX\X
\U section~1045.
\:\X1045:Cases of \\{main\_control} that are not part of the inner loop\X
\U section~1030.
\:\X1056, 1057, 1063\*, 1067, 1073, 1090\*, 1092, 1094, 1097, 1102, 1104, 1109,
1112, 1116, 1122\*, 1126, 1130, 1134, 1137, 1140, 1150, 1154, 1158, 1162, 1164,
1167, 1171, 1175, 1180, 1190, 1193:Cases of \\{main\_control} that build boxes
and lists\X
\U section~1045.
\:\X1210, 1268, 1271, 1274, 1276, 1285, 1290:Cases of \\{main\_control} that
don't depend on \\{mode}\X
\U section~1045.
\:\X227, 231, 239, 249, 266\*, 335, 377, 385, 412, 417, 469, 488, 492, 781,
984, 1053, 1059, 1072, 1089, 1108, 1115, 1143, 1157, 1170, 1179, 1189, 1209,
1220, 1223, 1231, 1251, 1255, 1261, 1263, 1273, 1278, 1287, 1292, 1295,
1346:Cases of \\{print\_cmd\_chr} for symbolic printing of primitives\X
\U section~298.
\:\X690:Cases of \\{show\_node\_list} that arise in mlists only\X
\U section~183\*.
\:\X345:Cases where character is ignored\X
\U section~344.
\:\X613:Change buffered instruction to \|y or \|w and \&{goto} \\{found}\X
\U section~612.
\:\X614:Change buffered instruction to \|z or \|x and \&{goto} \\{found}\X
\U section~612.
\:\X775:Change current mode to $-\\{vmode}$ for \.{\\halign}, $-\\{hmode}$ for %
\.{\\valign}\X
\U section~774.
\:\X882:Change discretionary to compulsory and set $\\{disc\_break}\K\\{true}$\X
\U section~881.
\:\X621:Change font \\{dvi\_f} to \|f\X
\U section~620\*.
\:\X344:Change state if necessary, and \&{goto} \\{switch} if the current
character should be ignored, or \&{goto} \\{reswitch} if the current character
changes to another\X
\U section~343.
\:\X1289:Change the case of the token in \|p, if a change is appropriate\X
\U section~1288.
\:\X763:Change the current style and \&{goto} \\{delete\_q}\X
\U section~761.
\:\X86:Change the interaction level and \&{return}\X
\U section~84\*.
\:\X731:Change this node to a style node followed by the correct choice, then %
\&{goto} \\{done\_with\_node}\X
\U section~730.
\:\X49\*:Character \|k cannot be printed\X
\U section~48.
\:\X244:Character \|s is the current new-line character\X
\U sections~58, 59, and~60.
\:\X170:Check flags of unavailable nodes\X
\U section~167.
\:\X570:Check for charlist cycle\X
\U section~569.
\:\X776:Check for improper alignment in displayed math\X
\U section~774.
\:\X974:Check if node \|p is a new champion breakpoint; then \(go)\&{goto} %
\\{done} if \|p is a forced break or if the page-so-far is already too full\X
\U section~972.
\:\X1005:Check if node \|p is a new champion breakpoint; then \(if)if it is
time for a page break, prepare for output, and either fire up the user's output
routine and \&{return} or ship out the page and \&{goto} \\{done}\X
\U section~997.
\:\X168:Check single-word \\{avail} list\X
\U section~167.
\:\X1197:Check that another \.\$ follows\X
\U sections~1194 and~1206.
\:\X1195:Check that the necessary fonts for math symbols are present; if not,
flush the current math lists and set $\\{danger}\K\\{true}$\X
\U section~1194.
\:\X899\*:Check that the nodes following \\{hb} permit hyphenation and that at
least five letters have been found, otherwise \&{goto} \\{done1}\X
\U section~894.
\:\X14, 111, 290, 522, 1249:Check the ``constant'' values for consistency\X
\U section~1332.
\:\X53:Check the pool check sum\X
\U section~52.
\:\X169:Check variable-size \\{avail} list\X
\U section~167.
\:\X865:Clean up the memory by removing the break nodes\X
\U sections~815 and~863.
\:\X650:Clear dimensions to zero\X
\U sections~649 and~668.
\:\X282:Clear off top level from \\{save\_stack}\X
\U section~281.
\:\X1329:Close the format file\X
\U section~1302.
\:\X451:Coerce glue to a dimension\X
\U sections~449 and~455.
\:\X9\*:Compiler directives\X
\U section~4.
\:\X723:Complain about an undefined family and set \\{cur\_i} null\X
\U section~722.
\:\X370:Complain about an undefined macro\X
\U section~367.
\:\X373:Complain about missing \.{\\endcsname}\X
\U section~372.
\:\X459:Complain about unknown unit and \&{goto} \\{done2}\X
\U section~458.
\:\X428:Complain that \.{\\the} can't do this; give zero result\X
\U section~413.
\:\X1166:Complain that the user should have said \.{\\mathaccent}\X
\U section~1165.
\:\X1185:Compleat the incompleat noad\X
\U section~1184.
\:\X1298:Complete a potentially long \.{\\show} command\X
\U section~1293.
\:\X1240:Compute result of \\{multiply} or \\{divide}, put it in \\{cur\_val}\X
\U section~1236.
\:\X1238:Compute result of \\{register} or \\{advance}, put it in \\{cur\_val}\X
\U section~1236.
\:\X741:Compute the amount of skew\X
\U section~738.
\:\X1007:Compute the badness, \|b, of the current page, using \\{awful\_bad} if
the box is too full\X
\U section~1005.
\:\X975:Compute the badness, \|b, using \\{awful\_bad} if the box is too full\X
\U section~974.
\:\X859:Compute the demerits, \|d, from \|r to \\{cur\_p}\X
\U section~855.
\:\X840:Compute the discretionary \\{break\_width} values\X
\U section~837.
\:\X261:Compute the hash code \|h\X
\U section~259.
\:\X765:Compute the magic offset\X
\U section~1337.
\:\X714:Compute the minimum suitable height, \|w, and the corresponding number
of extension steps, \|n; also set $\\{width}(\|b)$\X
\U section~713.
\:\X850:Compute the new line width\X
\U section~835.
\:\X1237:Compute the register location \|l and its type \|p; but \&{return} if
invalid\X
\U section~1236.
\:\X1239:Compute the sum of two glue specs\X
\U section~1238.
\:\X965:Compute the trie op code, \|v, and set $\|l\K0$\X
\U section~963.
\:\X837:Compute the values of \\{break\_width}\X
\U section~836.
\:\X612:Consider a node with matching width; \&{goto} \\{found} if it's a hit\X
\U section~611.
\:\X851:Consider the demerits for a line from \|r to \\{cur\_p}; deactivate
node \|r if it should no longer be active; then \&{goto} \\{continue} if a line
from \|r to \\{cur\_p} is infeasible, otherwise record a new feasible break\X
\U section~829.
\:\X11\*:Constants in the outer block\X
\U section~4.
\:\X750:Construct a box with limits above and below it, skewed by \\{delta}\X
\U section~749.
\:\X759:Construct a sub/superscript combination box \|x, with the superscript
offset by \\{delta}\X
\U section~756.
\:\X757:Construct a subscript box \|x when there is no superscript\X
\U section~756.
\:\X758:Construct a superscript box \|x\X
\U section~756.
\:\X747:Construct a vlist box for the fraction, according to \\{shift\_up} and %
\\{shift\_down}\X
\U section~743.
\:\X713:Construct an extensible character in a new box \|b, using recipe $%
\\{rem\_byte}(\|q)$ and font \|f\X
\U section~710.
\:\X399:Contribute an entire group to the current parameter\X
\U section~392.
\:\X397:Contribute the recently matched tokens to the current parameter, and %
\&{goto} \\{continue} if a partial match is still in effect; but abort if $\|s=%
\\{null}$\X
\U section~392.
\:\X729:Convert \(a)a final \\{bin\_noad} to an \\{ord\_noad}\X
\U sections~726 and~728.
\:\X429:Convert \(c)\\{cur\_val} to a lower level\X
\U section~413.
\:\X732:Convert \(m)math glue to ordinary glue\X
\U section~730.
\:\X754:Convert \(n)$\\{nucleus}(\|q)$ to an hlist and attach the
sub/superscripts\X
\U section~728.
\:\X795:Copy the tabskip glue between columns\X
\U section~791.
\:\X794:Copy the templates from node \\{cur\_loop} into node \|p\X
\U section~793.
\:\X466:Copy the token list\X
\U section~465.
\:\X755:Create a character node \|p for $\\{nucleus}(\|q)$, possibly followed
by a kern node for the italic correction, and set \\{delta} to the italic
correction if a subscript is present\X
\U section~754.
\:\X1124\*:Create a character node \|q for the next character, but set $\|q\K%
\\{null}$ if problems arise\X
\U section~1123.
\:\X462:Create a new glue specification whose width is \\{cur\_val}; scan for
its stretch and shrink components\X
\U section~461.
\:\X1009:Create a page insertion node with $\\{subtype}(\|r)=\\{qi}(\|n)$, and
include the glue correction for box \|n in the current page state\X
\U section~1008.
\:\X864:Create an active breakpoint representing the beginning of the paragraph%
\X
\U section~863.
\:\X914:Create and append a discretionary node as an alternative to the
ligature, and continue to develop both branches until they become equivalent\X
\U section~913.
\:\X744:Create equal-width boxes \|x and \|z for the numerator and denominator,
and compute the default amounts \\{shift\_up} and \\{shift\_down} by which they
are displaced from the baseline\X
\U section~743.
\:\X836:Create new active nodes for the best feasible breaks just found\X
\U section~835.
\:\X1328:Create the \\{format\_ident}, open the format file, and inform the
user that dumping has begun\X
\U section~1302.
\:\X224:Current \\{mem} equivalent of glue parameter number \|n\X
\U sections~152 and~154.
\:\X860:Deactivate node \|r\X
\U section~851.
\:\X1043, 1047, 1049, 1050, 1051, 1054, 1060, 1061, 1064, 1069, 1070, 1075,
1079, 1084, 1086, 1091, 1093, 1095, 1096, 1099, 1101, 1103, 1105, 1110, 1113,
1117, 1119, 1123, 1127, 1129, 1131, 1135, 1136, 1138, 1142, 1151, 1155, 1159,
1160, 1163, 1165, 1172, 1174, 1176, 1181, 1191, 1194, 1200, 1211, 1270, 1275,
1279, 1288, 1293, 1302, 1348:Declare action procedures for use by \\{main%
\_control}\X
\U section~1030.
\:\X734, 735, 736, 737, 738, 743, 749, 752, 756, 762:Declare math construction
procedures\X
\U section~726.
\:\X944, 947, 948, 949, 951, 953, 957, 959, 960:Declare procedures for
preprocessing hyphenation patterns\X
\U section~942.
\:\X691, 692, 694:Declare procedures needed for displaying the elements of
mlists\X
\U section~179.
\:\X1349, 1350:Declare procedures needed in \\{do\_extension}\X
\U section~1348.
\:\X1368, 1370, 1373:Declare procedures needed in \\{hlist\_out}, \\{vlist%
\_out}\X
\U section~619.
\:\X577, 578:Declare procedures that scan font-related stuff\X
\U section~409.
\:\X432, 433, 434, 435\*, 436, 437:Declare procedures that scan restricted
classes of integers\X
\U section~409.
\:\X826, 829, 877, 895:Declare subprocedures for \\{line\_break}\X
\U section~815.
\:\X1215, 1229, 1236, 1243, 1244, 1245, 1246, 1247, 1257, 1265:Declare
subprocedures for \\{prefixed\_command}\X
\U section~1211.
\:\X709, 711, 712:Declare subprocedures for \\{var\_delimiter}\X
\U section~706.
\:\X1184:Declare the function called \\{fin\_mlist}\X
\U section~1174.
\:\X524:Declare the function called \\{open\_fmt\_file}\X
\U section~1303.
\:\X906:Declare the function called \\{reconstitute}\X
\U section~895.
\:\X785:Declare the procedure called \\{align\_peek}\X
\U section~800.
\:\X1012:Declare the procedure called \\{fire\_up}\X
\U section~994.
\:\X782:Declare the procedure called \\{get\_preamble\_token}\X
\U section~774.
\:\X1068\*:Declare the procedure called \\{handle\_right\_brace}\X
\U section~1030.
\:\X787:Declare the procedure called \\{init\_span}\X
\U section~786.
\:\X379:Declare the procedure called \\{insert\_relax}\X
\U section~366\*.
\:\X389:Declare the procedure called \\{macro\_call}\X
\U section~366\*.
\:\X298:Declare the procedure called \\{print\_cmd\_chr}\X
\U section~252.
\:\X225:Declare the procedure called \\{print\_skip\_param}\X
\U section~179.
\:\X284:Declare the procedure called \\{restore\_trace}\X
\U section~281.
\:\X306:Declare the procedure called \\{runaway}\X
\U section~119.
\:\X292:Declare the procedure called \\{show\_token\_list}\X
\U section~119.
\:\X346:Decry the invalid character and \&{goto} \\{restart}\X
\U section~344.
\:\X1019:Delete the page-insertion nodes\X
\U section~1014.
\:\X88:Delete $\|c-\.{"0"}$ tokens and \&{goto} \\{continue}\X
\U section~84\*.
\:\X883:Destroy the \|t nodes following \|q, but save the last one if it is a
necessary kern; make \|r point to the following node\X
\U section~882.
\:\X664:Determine horizontal glue shrink setting, then \&{return} or \hbox{%
\&{goto} \\{common\_ending}}\X
\U section~657.
\:\X658:Determine horizontal glue stretch setting, then \&{return} or \hbox{%
\&{goto} \\{common\_ending}}\X
\U section~657.
\:\X1202:Determine the displacement, \|d, of the left edge of the equation,
with respect to the line size \|z, assuming that $\|l=\\{false}$\X
\U section~1199.
\:\X665:Determine the shrink order\X
\U sections~664, 676, and~796.
\:\X659:Determine the stretch order\X
\U sections~658, 673, and~796.
\:\X672:Determine the value of $\\{height}(\|r)$ and the appropriate glue
setting; then \&{return} or \&{goto} \\{common\_ending}\X
\U section~668.
\:\X657:Determine the value of $\\{width}(\|r)$ and the appropriate glue
setting; then \&{return} or \&{goto} \\{common\_ending}\X
\U section~649.
\:\X676:Determine vertical glue shrink setting, then \&{return} or \hbox{%
\&{goto} \\{common\_ending}}\X
\U section~672.
\:\X673:Determine vertical glue stretch setting, then \&{return} or \hbox{%
\&{goto} \\{common\_ending}}\X
\U section~672.
\:\X1212:Discard erroneous prefixes and \&{return}\X
\U section~1211.
\:\X1213:Discard the prefixes \.{\\long} and \.{\\outer} if they are irrelevant%
\X
\U section~1211.
\:\X978:Dispense with trivial cases of void or bad boxes\X
\U section~977.
\:\X197:Display adjustment \|p\X
\U section~183\*.
\:\X184:Display box \|p\X
\U section~183\*.
\:\X695:Display choice node \|p\X
\U section~690.
\:\X195:Display discretionary \|p\X
\U section~183\*.
\:\X697:Display fraction noad \|p\X
\U section~690.
\:\X189:Display glue \|p\X
\U section~183\*.
\:\X1011:Display insertion split cost\X
\U section~1010.
\:\X188:Display insertion \|p\X
\U section~183\*.
\:\X191:Display kern \|p\X
\U section~183\*.
\:\X190:Display leaders \|p\X
\U section~189.
\:\X193:Display ligature \|p\X
\U section~183\*.
\:\X196:Display mark \|p\X
\U section~183\*.
\:\X192:Display math node \|p\X
\U section~183\*.
\:\X183\*:Display node \|p\X
\U section~182.
\:\X696:Display normal noad \|p\X
\U section~690.
\:\X1006:Display page break cost\X
\U section~1005.
\:\X194:Display penalty \|p\X
\U section~183\*.
\:\X187:Display rule \|p\X
\U section~183\*.
\:\X185:Display special fields of the unset node \|p\X
\U section~184.
\:\X312:Display the current context\X
\U section~311.
\:\X294:Display the token $(\|m,\|c)$\X
\U section~293.
\:\X502:Display the value of \|b\X
\U section~498.
\:\X186:Display the value of $\\{glue\_set}(\|p)$\X
\U section~184.
\:\X1356:Display the whatsit node \|p\X
\U section~183\*.
\:\X293:Display token \|p, and \&{return} if there are problems\X
\U section~292.
\:\X728:Do first-pass processing based on $\\{type}(\|q)$; \&{goto} \\{done%
\_with\_noad} if a noad has been fully processed, \&{goto} \\{check%
\_dimensions} if it has been translated into $\\{new\_hlist}(\|q)$, or \&{goto}
\\{done\_with\_node} if a node has been fully processed\X
\U section~727.
\:\X320:Do magic computation\X
\U section~292.
\:\X1374:Do some work that has been queued up for \.{\\write}\X
\U section~1373.
\:\X1066:Drop current token and complain that it was unmatched\X
\U section~1064.
\:\X1326:Dump a couple more things and the closing check word\X
\U section~1302.
\:\X1307:Dump constants for consistency check\X
\U section~1302.
\:\X1315:Dump regions 1 to 4 of \\{eqtb}\X
\U section~1313.
\:\X1316:Dump regions 5 and 6 of \\{eqtb}\X
\U section~1313.
\:\X1322:Dump the array info for internal font number \|k\X
\U section~1320.
\:\X1311:Dump the dynamic memory\X
\U section~1302.
\:\X1320:Dump the font information\X
\U section~1302.
\:\X1318:Dump the hash table\X
\U section~1313.
\:\X1324:Dump the hyphenation tables\X
\U section~1302.
\:\X1309:Dump the string pool\X
\U section~1302.
\:\X1313:Dump the table of equivalents\X
\U section~1302.
\:\X1022:Either append the insertion node \|p after node \|q, and remove it
from the current page, or delete $\\{node}(\|p)$\X
\U section~1020.
\:\X1020:Either insert the material specified by node \|p into the appropriate
box, or hold it for the next page; also delete node \|p from the current page\X
\U section~1014.
\:\X501:Either process \.{\\ifcase} or set \|b to the value of a boolean
condition\X
\U section~498.
\:\X599:Empty the last bytes out of \\{dvi\_buf}\X
\U section~642\*.
\:\X1028:Ensure that box 255 is empty after output\X
\U section~1026.
\:\X1015:Ensure that box 255 is empty before output\X
\U section~1014.
\:\X954:Ensure that $\\{trie\_max}\G\|h+128$\X
\U section~953.
\:\X939:Enter a hyphenation exception\X
\U section~935.
\:\X961:Enter all of the patterns into a linked trie, until coming to a right
brace; then skip an optional space\X
\U section~960.
\:\X935:Enter as many hyphenation exceptions as are listed, until coming to a
right brace; then skip an optional space and \&{return}\X
\U section~934.
\:\X349:Enter \\{skip\_blanks} state, emit a space\X
\U section~347.
\:\X34\*, 78, 81, 82, 93, 94, 95:Error handling procedures\X
\U section~4.
\:\X651:Examine node \|p in the hlist, taking account of its effect on the
dimensions of the new box, or moving it to the adjustment list; then advance %
\|p to the next node\X
\U section~649.
\:\X669:Examine node \|p in the vlist, taking account of its effect on the
dimensions of the new box; then advance \|p to the next node\X
\U section~668.
\:\X367:Expand a nonmacro\X
\U section~366\*.
\:\X1371:Expand macros in the token list and make $\\{link}(\\{def\_ref})$
point to the result\X
\U section~1370.
\:\X478:Expand the next part of the input\X
\U section~477.
\:\X368:Expand the token after the next token\X
\U section~367.
\:\X1024:Explain that too many dead cycles have occurred in a row\X
\U section~1012.
\:\X446:Express astonishment that no number was here\X
\U section~444.
\:\X1128:Express consternation over the fact that no alignment is in progress\X
\U section~1127.
\:\X475:Express shock at the missing left brace; \&{goto} \\{found}\X
\U section~474.
\:\X1040:Extend a ligature, \&{goto} \\{main\_loop\_3}\X
\U section~1037.
\:\X390:Feed the macro body and its parameters to the scanner\X
\U section~389.
\:\X420:Fetch a box dimension\X
\U section~413.
\:\X414:Fetch a character code from some table\X
\U section~413.
\:\X425:Fetch a font dimension\X
\U section~413.
\:\X426:Fetch a font integer\X
\U section~413.
\:\X427:Fetch a register\X
\U section~413.
\:\X415:Fetch a token list or font identifier, provided that $\\{level}=\\{tok%
\_val}$\X
\U section~413.
\:\X449:Fetch an internal dimension and \&{goto} \\{attach\_sign}, or fetch an
internal integer\X
\U section~448\*.
\:\X424:Fetch an item in the current node, if appropriate\X
\U section~413.
\:\X421:Fetch something on the \\{page\_so\_far}\X
\U section~413.
\:\X419:Fetch the \\{dead\_cycles} or the \\{insert\_penalties}\X
\U section~413.
\:\X423:Fetch the \\{par\_shape} size\X
\U section~413.
\:\X422:Fetch the \\{prev\_graf}\X
\U section~413.
\:\X418:Fetch the \\{space\_factor} or the \\{prev\_depth}\X
\U section~413.
\:\X874:Find an active node with fewest demerits\X
\U section~873.
\:\X923:Find hyphen locations for the word in \\{hc}\X
\U section~895.
\:\X863:Find optimal breakpoints\X
\U section~815.
\:\X875:Find the best active node for the desired looseness\X
\U section~873.
\:\X1010:Find the best way to split the insertion, and change $\\{type}(\|r)$
to \\{split\_up}\X
\U section~1008.
\:\X1042:Find the glue specification, \|p, for text spaces in the current font\X
\U sections~1041 and~1043.
\:\X1206:Finish an alignment in a display\X
\U section~812.
\:\X1199:Finish displayed math\X
\U section~1194.
\:\X663\*:Finish issuing a diagnostic message for an overfull or underfull hbox%
\X
\U section~649.
\:\X675\*:Finish issuing a diagnostic message for an overfull or underfull vbox%
\X
\U section~668.
\:\X351:Finish line, emit a \.{\\par}\X
\U section~347.
\:\X348:Finish line, emit a space\X
\U section~347.
\:\X350:Finish line, \&{goto} \\{switch}\X
\U section~347.
\:\X1196:Finish math in text\X
\U section~1194.
\:\X642\*:Finish the \.{DVI} file\X
\U section~1333\*.
\:\X1367:Finish the extensions\X
\U section~1333\*.
\:\X1025:Fire up the user's output routine and \&{return}\X
\U section~1012.
\:\X430:Fix the reference count, if any, and negate \\{cur\_val} if %
\\{negative}\X
\U section~413.
\:\X639:Flush the box from memory, showing statistics if requested\X
\U section~638.
\:\X1037:Follow the lig/kern program; \&{goto} \\{main\_loop\_3} if scoring a
hit\X
\U section~1036.
\:\X1048, 1098, 1111, 1144:Forbidden cases detected in \\{main\_control}\X
\U section~1045.
\:\X610:Generate a \\{down} or \\{right} command for \|w and \&{return}\X
\U section~607.
\:\X609:Generate a \\{y0} or \\{z0} command in order to reuse a previous
appearance of~\|w\X
\U section~607.
\:\X816, 827, 834, 848:Get ready to start line breaking\X
\U section~815.
\:\X1337:Get the first line of input and prepare to start\X
\U section~1332.
\:\X406:Get the next non-blank non-call token\X
\U sections~405, 441, 455, 503, 526, 577, 785, 791, and~1045.
\:\X404:Get the next non-blank non-relax non-call token\X
\U sections~403, 1078, 1084, 1151, 1160, 1211, 1226, and~1270.
\:\X441:Get the next non-blank non-sign token; set \\{negative} appropriately\X
\U sections~440\*, 448\*, and~461.
\:\X358:Get the next token, suppressing expansion\X
\U section~357.
\:\X83:Get user's advice and \&{return}\X
\U section~82.
\:\X1031:Give diagnostic information, if requested\X
\U section~1030.
\:\X936:Give improper \.{\\hyphenation} error\X
\U section~935.
\:\X13, 20, 26, 30\*, 39, 50, 54, 73, 76, 79, 96, 104, 115, 116\*, 117, 118,
124, 165, 173, 181, 213, 246, 253, 256, 271, 286, 297, 301, 304\*, 305, 308,
309, 310, 333, 361, 382, 387, 388, 410, 438, 447, 480, 489, 493\*, 512, 513\*,
520\*, 527, 532, 539, 549, 550, 555, 592, 595\*, 605, 616, 646, 647, 661, 684,
719, 724, 764, 770, 814, 821, 823, 825, 828, 833, 839, 847, 872, 892, 900, 905,
921, 926, 943, 945, 946, 950, 971, 980, 982, 989, 1074, 1266, 1281, 1299, 1305,
1331, 1342, 1345, 1377\*, 1379\*:Global variables\X
\U section~4.
\:\X1145:Go into display math mode\X
\U section~1138.
\:\X1139:Go into ordinary math mode\X
\U sections~1138 and~1142.
\:\X801:Go through the preamble list, determining the column widths and
changing the alignrecords to dummy unset boxes\X
\U section~800.
\:\X126:Grow more variable-size memory and \&{goto} \\{restart}\X
\U section~125.
\:\X347:Handle situations involving spaces, braces, changes of state\X
\U section~344.
\:\X835:If a line number class has ended, create new active nodes for the best
feasible breaks in that class; then \&{return} if $\|r=\\{last\_active}$,
otherwise compute the new \\{line\_width}\X
\U section~829.
\:\X955:If all characters of the family fit relative to \|h, then \&{goto} %
\\{found},\30\ otherwise \&{goto} \\{not\_found}\X
\U section~953.
\:\X342:If an alignment entry has just ended, take appropriate action\X
\U section~341\*.
\:\X355:If an expanded control code is present, reduce it and \&{goto} \\{start%
\_cs}\X
\U sections~354 and~356.
\:\X1304:If dumping is not allowed, abort\X
\U section~1302.
\:\X753:If instruction \\{cur\_i} is a kern with \\{cur\_c}, attach the kern
after \|q and \&{return}; or if it is a ligature with \\{cur\_c}, combine noads
\|q and \|p and \&{goto} \\{restart}\X
\U section~752.
\:\X902:If no hyphens were found, \&{return}\X
\U section~895.
\:\X868:If node \\{cur\_p} is a legal breakpoint, call \\{try\_break}\X
\U section~866.
\:\X972:If node \|p is a legal breakpoint, check if this break is the best
known, and \&{goto} \\{done} if \|p is null or if the page-so-far is already
too full to accept more stuff\X
\U section~970.
\:\X761:If node \|q is a style node, change the style and \&{goto} \\{delete%
\_q}; otherwise if it is not a noad, put it into the hlist, advance \|q, and %
\&{goto} \\{done}; otherwise set \|s to the size of noad \|q, set \|t to the
associated type ($\\{ord\_noad}\to\\{inner\_noad}$), and set \\{pen} to the
associated penalty\X
\U section~760.
\:\X832:If node \|r is of type \\{delta\_node}, update \\{cur\_active\_width},
set \\{prev\_r} and \\{prev\_prev\_r}, then \&{goto} \\{continue}\X
\U section~829.
\:\X1080:If the current list ends with a box node, delete it from the list and
make \\{cur\_box} point to it; otherwise set $\\{cur\_box}\K\\{null}$\X
\U section~1079.
\:\X1000:If the current page is empty and node \|p is to be deleted, \&{goto} %
\\{done1}; otherwise use node \|p to update the state of the current page; if
this node is an insertion, \&{goto} \\{contribute}; otherwise if this node is
not a legal breakpoint, \&{goto} \\{contribute} or \\{update\_heights};
otherwise set \\{pi} to the penalty associated with this breakpoint\X
\U section~997.
\:\X910:If the list has more than one element, create a ligature node\X
\U section~906.
\:\X476:If the next character is a parameter number, make \\{cur\_tok} a %
\\{match} token; but if it is a left brace, store `\\{left\_brace}, \\{end%
\_match}', set \\{hash\_brace}, and \&{goto} \\{done}\X
\U section~474.
\:\X792:If the preamble list has been traversed, check that the row has ended\X
\U section~791.
\:\X1227:If the right-hand side is a token parameter or token register, finish
the assignment and \&{goto} \\{done}\X
\U section~1226.
\:\X931:If the string $\\{hyph\_word}[\|h]$ is less than \(hc)$\\{hc}[1\to%
\\{hn}]$, \&{goto} \\{not\_found}; but if the two strings are equal, set %
\\{hyf} to the hyphen positions and \&{goto} \\{found}\X
\U section~930.
\:\X941:If the string $\\{hyph\_word}[\|h]$ is less than \(or)or equal to \|s,
interchange $(\\{hyph\_word}[\|h],\\{hyph\_list}[\|h])$ with $(\|s,\|p)$\X
\U section~940.
\:\X1260:If this font has already been loaded, set \|f to the internal font
number and \&{goto} \\{common\_ending}\X
\U section~1257.
\:\X352:If this \\{sup\_mark} starts a control character like~\.{\↑\↑A}, then %
\&{goto} \\{reswitch}, otherwise set $\\{state}\K\\{mid\_line}$\X
\U section~344.
\:\X1183:Ignore the fraction operation and complain about this ambiguous case\X
\U section~1181.
\:\X1353:Implement \.{\\closeout}\X
\U section~1348.
\:\X1375:Implement \.{\\immediate}\X
\U section~1348.
\:\X1351:Implement \.{\\openout}\X
\U section~1348.
\:\X1354:Implement \.{\\special}\X
\U section~1348.
\:\X1352:Implement \.{\\write}\X
\U section~1348.
\:\X1359:Incorporate a whatsit node into a vbox\X
\U section~669.
\:\X1360:Incorporate a whatsit node into an hbox\X
\U section~651.
\:\X653:Incorporate box dimensions into the dimensions of the hbox that will
contain~it\X
\U section~651.
\:\X670:Incorporate box dimensions into the dimensions of the vbox that will
contain~it\X
\U section~669.
\:\X654\*:Incorporate character dimensions into the dimensions of the hbox that
will contain~it, then move to the next node\X
\U section~651.
\:\X656:Incorporate glue into the horizontal totals\X
\U section~651.
\:\X671:Incorporate glue into the vertical totals\X
\U section~669.
\:\X580:Increase the number of parameters in the last font\X
\U section~578.
\:\X164, 222, 228, 232\*, 240, 250, 258, 552, 952, 1216, 1301, 1369:Initialize
table entries (done by \.{INITEX} only)\X
\U section~8\*.
\:\X1001:Initialize the current page, insert the \.{\\topskip} glue ahead of %
\|p, and \&{goto} \\{continue}\X
\U section~1000.
\:\X331:Initialize the input routines\X
\U section~1337.
\:\X55, 61, 528, 533:Initialize the output routines\X
\U section~1332.
\:\X75:Initialize the print \\{selector} based on \\{interaction}\X
\U sections~1265 and~1337.
\:\X790, 797, 820, 981, 988:Initialize the special list heads and constant
nodes\X
\U section~164.
\:\X617:Initialize variables as \\{ship\_out} begins\X
\U section~640.
\:\X8\*:Initialize whatever \TeX\ might access\X
\U section~4.
\:\X378:Initiate or terminate input from a file\X
\U section~367.
\:\X1083:Initiate the construction of an hbox or vbox, then \&{return}\X
\U section~1079.
\:\X483:Input and store tokens from the next line of the file\X
\U section~482.
\:\X484:Input for \.{\\read} from the terminal\X
\U section~483.
\:\X343:Input from external file, \&{goto} \\{restart} if no input found\X
\U section~341\*.
\:\X357:Input from token list, \&{goto} \\{restart} if end of list or if a
parameter needs to be expanded\X
\U section~341\*.
\:\X485\*:Input the first line of $\\{read\_file}[\|m]$\X
\U section~483.
\:\X486:Input the next line of $\\{read\_file}[\|m]$\X
\U section~483.
\:\X843:Insert a delta node to prepare for breaks at \\{cur\_p}\X
\U section~836.
\:\X844:Insert a delta node to prepare for the next active node\X
\U section~836.
\:\X918:Insert a discretionary hyphen after \|s\X
\U section~913.
\:\X1177:Insert a dummy noad to be sub/superscripted\X
\U section~1176.
\:\X845:Insert a new active node from $\\{best\_place}[\\{fit\_class}]$ to %
\\{cur\_p}\X
\U section~836.
\:\X260:Insert a new control sequence after \|p, then make \|p point to it\X
\U section~259.
\:\X963:Insert a new pattern into the linked trie\X
\U section~961.
\:\X964:Insert a new trie node between \|q and \|p, and make \|p point to it\X
\U section~963.
\:\X1269:Insert a token saved by \.{\\afterassignment}, if any\X
\U section~1211.
\:\X375:Insert a \\{frozen\_endv} token\X
\U section~366\*.
\:\X969:Insert glue for \\{split\_top\_skip} and set~$\|p\K\\{null}$\X
\U section~968.
\:\X932:Insert hyphens as specified in $\\{hyph\_list}[\|h]$\X
\U section~931.
\:\X359:Insert macro parameter and \&{goto} \\{restart}\X
\U section~357.
\:\X386:Insert the \(a)appropriate mark text into the scanner\X
\U section~367.
\:\X812:Insert the \(c)current list into its environment\X
\U section~800.
\:\X940:Insert the \(p)pair $(\|s,\|p)$ into the exception table\X
\U section~939.
\:\X789:Insert the \(v)\<v_j> template and \&{goto} \\{restart}\X
\U section~342.
\:\X326:Insert token \|p into \TeX's input\X
\U section~282.
\:\X84\*:Interpret code \|c and \&{return} if done\X
\U section~83.
\:\X87:Introduce new material from the terminal and \&{return}\X
\U section~84\*.
\:\X579:Issue an error message if $\\{cur\_val}=\\{fmem\_ptr}$\X
\U section~578.
\:\X880:Justify the line ending at breakpoint \\{cur\_p}, and append it to the
current vertical list, together with associated penalties and other insertions\X
\U section~877.
\:\X6:Labels in the outer block\X
\U section~4.
\:\X1333\*, 1335\*, 1336, 1338:Last-minute procedures\X
\U section~1330.
\:\X793:Lengthen the preamble periodically\X
\U section~792.
\:\X627:Let \\{cur\_h} be the position of the first box, and set $\\{leader%
\_wd}+\\{lx}$ to the spacing between corresponding parts of boxes\X
\U section~626.
\:\X636:Let \\{cur\_v} be the position of the first box, and set $\\{leader%
\_ht}+\\{lx}$ to the spacing between corresponding parts of boxes\X
\U section~635.
\:\X1147\*:Let \|d be the natural width of node \|p; if the node is
``visible,'' \&{goto} \\{found}; if the node is glue that stretches or shrinks,
set $\|v\K\\{max\_dimen}$\X
\U section~1146.
\:\X1148:Let \|d be the natural width of this glue; if stretching or shrinking,
set $\|v\K\\{max\_dimen}$; \&{goto} \\{found} in the case of leaders\X
\U section~1147\*.
\:\X1361:Let \|d be the width of the whatsit \|p\X
\U section~1147\*.
\:\X1233:Let \|n be the largest legal code value, based on \\{cur\_chr}\X
\U section~1232.
\:\X998:Link node \|p into the current page and \&{goto} \\{done}\X
\U section~997.
\:\X450:Local variables for dimension calculations\X
\U section~448\*.
\:\X1198:Local variables for finishing a displayed formula\X
\U section~1194.
\:\X315:Local variables for formatting calculations\X
\U section~311.
\:\X901, 912, 922, 929:Local variables for hyphenation\X
\U section~895.
\:\X19, 163, 927:Local variables for initialization\X
\U section~4.
\:\X862, 893:Local variables for line breaking\X
\U section~815.
\:\X1032:Local variables for the inner loop of \\{main\_control}\X
\U section~1030.
\:\X1036:Look ahead for ligature or kerning, either continuing the main loop or
going to \\{reswitch}\X
\U section~1035.
\:\X979:Look at all the marks in nodes before the break, and set the final link
to \\{null} at the break\X
\U section~977.
\:\X708:Look at the list of characters starting with \|x in font \|g; set \|f
and \|c whenever a better character is found; \&{goto} \\{found} as soon as a
large enough variant is encountered\X
\U section~707.
\:\X611:Look at the other stack entries until deciding what sort of \.{DVI}
command to generate; \&{goto} \\{found} if node \|p is a ``hit''\X
\U section~607.
\:\X707:Look at the variants of $(\|z,\|x)$; set \|f and \|c whenever a better
character is found; \&{goto} \\{found} as soon as a large enough variant is
encountered\X
\U section~706.
\:\X908:Look for a ligature or kern between \|d and the following character;
update the data structure and \&{goto} \\{continue} if a ligature is found,
otherwise update~\|w and \&{goto} \\{done}\X
\U section~907.
\:\X479:Look for parameter number or \.{\#\#}\X
\U section~477.
\:\X930:Look for the word $\\{hc}[1\to\\{hn}]$ in the exception table, and %
\&{goto} \\{found} (with \\{hyf} containing the hyphens) if an entry is found\X
\U section~923.
\:\X374:Look up the characters of list \|r in the hash table, and set \\{cur%
\_cs}\X
\U section~372.
\:\X205:Make a copy of node \|p in node \|r\X
\U section~204.
\:\X1039:Make a ligature node, if \\{ligature\_present}; insert a discretionary
node for an explicit hyphen, if \|c is the current \\{hyphen\_char}\X
\U sections~1036 and~1038.
\:\X1357:Make a partial copy of the whatsit node \|p and make \|r point to it;
set \\{words} to the number of initial words not yet copied\X
\U section~206.
\:\X760:Make a second pass over the mlist, removing all noads and inserting the
proper spacing and penalties\X
\U section~726.
\:\X576:Make final adjustments and \&{goto} \\{done}\X
\U section~562.
\:\X652:Make node \|p look like a \\{char\_node} and \&{goto} \\{reswitch}\X
\U sections~622, 651, and~1147\*.
\:\X1003:Make sure that \\{page\_max\_depth} is not exceeded\X
\U section~997.
\:\X831:Make sure that \\{pi} is in the proper range\X
\U section~829.
\:\X995:Make the contribution list empty by setting its tail to \\{contrib%
\_head}\X
\U section~994.
\:\X48:Make the first 128 strings\X
\U section~47.
\:\X739:Make the height of box \|y equal to \|h\X
\U section~738.
\:\X806:Make the running dimensions in rule \|q extend to the boundaries of the
alignment\X
\U section~805.
\:\X811:Make the unset node \|r into a \\{vlist\_node} of height \|w, setting
the glue as if the height were \|t\X
\U section~808.
\:\X810:Make the unset node \|r into an \\{hlist\_node} of width \|w, setting
the glue as if the width were \|t\X
\U section~808.
\:\X710:Make variable \|b point to a box for $(\|f,\|c)$\X
\U section~706.
\:\X372:Manufacture a control sequence name\X
\U section~367.
\:\X1046\*:Math-only cases in non-math modes, or vice versa\X
\U section~1045.
\:\X803:Merge the widths in the span nodes of \|q with those of \|p, destroying
the span nodes of \|q\X
\U section~801.
\:\X881:Modify the end of the line to reflect the nature of the break and to
include \.{\\rightskip}; also set the proper value of \\{disc\_break}\X
\U section~880.
\:\X1044:Modify the glue specification in \|p according to the space factor\X
\U section~1043.
\:\X634:Move down or output leaders\X
\U section~631.
\:\X997:Move node \|p to the current page; if it is time for a page break, put
the nodes following the break back onto the contribution list, and \&{return}
to the user's output routine if there is one\X
\U section~994.
\:\X917:Move pointer \|s to the end of the current list, and set $\\{replace%
\_count}(\|r)$ appropriately\X
\U section~914.
\:\X625:Move right or output leaders\X
\U section~622.
\:\X898:Move the characters of a ligature node to \\{hu} and \\{hc}; but %
\&{goto} \\{done3} if they are not all letters\X
\U section~897.
\:\X958:Move the data into \\{trie}\X
\U section~966.
\:\X360:Move to next line of file, or \&{goto} \\{restart} if there is no next
line, or \&{return} if a \.{\\read} line has finished\X
\U section~343.
\:\X431:Negate all three glue components of \\{cur\_val}\X
\U section~430.
\:\X802:Nullify $\\{width}(\|q)$ and the tabskip glue following this column\X
\U section~801.
\:\X1339:Numbered cases for \\{debug\_help}\X
\U section~1338.
\:\X563:Open \\{tfm\_file} for input\X
\U section~562.
\:\X830:Other local variables for \\{try\_break}\X
\U section~829.
\:\X632:Output a box in a vlist\X
\U section~631.
\:\X623:Output a box in an hlist\X
\U section~622.
\:\X628:Output a leader box at \\{cur\_h}, then advance \\{cur\_h} by $%
\\{leader\_wd}+\\{lx}$\X
\U section~626.
\:\X637:Output a leader box at \\{cur\_v}, then advance \\{cur\_v} by $%
\\{leader\_ht}+\\{lx}$\X
\U section~635.
\:\X633:Output a rule in a vlist, \&{goto} \\{next\_p}\X
\U section~631.
\:\X624:Output a rule in an hlist\X
\U section~622.
\:\X635:Output leaders in a vlist, \&{goto} \\{fin\_rule} if a rule or to %
\\{next\_p} if done\X
\U section~634.
\:\X626:Output leaders in an hlist, \&{goto} \\{fin\_rule} if a rule or to %
\\{next\_p} if done\X
\U section~625.
\:\X620\*:Output node \|p for \\{hlist\_out} and move to the next node,
maintaining the condition $\\{cur\_v}=\\{base\_line}$\X
\U section~619.
\:\X630:Output node \|p for \\{vlist\_out} and move to the next node,
maintaining the condition $\\{cur\_h}=\\{left\_edge}$\X
\U section~629.
\:\X1334:Output statistics about this job\X
\U section~1333\*.
\:\X643:Output the font definitions for all fonts that were used\X
\U section~642\*.
\:\X603:Output the font name whose internal number is \|f\X
\U section~602.
\:\X622:Output the non-\\{char\_node} \|p for \\{hlist\_out} and move to the
next node\X
\U section~620\*.
\:\X631:Output the non-\\{char\_node} \|p for \\{vlist\_out}\X
\U section~630.
\:\X1365:Output the whatsit node \|p in a vlist\X
\U section~631.
\:\X1366:Output the whatsit node \|p in an hlist\X
\U section~622.
\:\X956:Pack the family into \\{trie} relative to \|h\X
\U section~953.
\:\X966:Pack the trie\X
\U section~960.
\:\X796:Package an unset box for the current column and record its width\X
\U section~791.
\:\X804:Package the preamble list, to determine the actual tabskip glue
amounts, and let \|p point to this prototype box\X
\U section~800.
\:\X1023:Perform the default output routine\X
\U section~1012.
\:\X1207:Pontificate about improper alignment in display\X
\U section~1206.
\:\X496:Pop the condition stack\X
\U sections~498, 500, 509, and~510.
\:\X1018:Prepare all the boxes involved in insertions to act as queues\X
\U section~1014.
\:\X854:Prepare to deactivate node~\|r, and \&{goto} \\{deactivate} unless
there is a reason to consider lines of text from \|r to \\{cur\_p}\X
\U section~851.
\:\X1065:Prepare to insert a token that matches \\{cur\_group}, and print what
it is\X
\U section~1064.
\:\X1002:Prepare to move a box or rule node to the current page, then \&{goto} %
\\{contribute}\X
\U section~1000.
\:\X1363:Prepare to move whatsit \|p to the current page, then \&{goto} %
\\{contribute}\X
\U section~1000.
\:\X175:Print a short indication of the contents of node \|p\X
\U section~174\*.
\:\X846:Print a symbolic description of the new break node\X
\U section~845.
\:\X856:Print a symbolic description of this feasible break\X
\U section~855.
\:\X339:Print either `\.{definition}' or `\.{use}' or `\.{preamble}' or `%
\.{text}', and insert tokens that should lead to recovery\X
\U section~338.
\:\X313\*:Print location of current line\X
\U section~312.
\:\X171:Print newly busy locations\X
\U section~167.
\:\X1283:Print string \|s as an error message\X
\U section~1279.
\:\X1280:Print string \|s on the terminal\X
\U section~1279.
\:\X536:Print the banner line, including the date and time\X
\U section~534.
\:\X267:Print the font identifier for $\\{font}(\|p)$\X
\U sections~174\* and~176\*.
\:\X89:Print the help information and \&{goto} \\{continue}\X
\U section~84\*.
\:\X857:Print the list between \\{printed\_node} and \\{cur\_p}, then set $%
\\{printed\_node}\K\\{cur\_p}$\X
\U section~856.
\:\X85:Print the menu of available options\X
\U section~84\*.
\:\X472:Print the result of command \|c\X
\U section~470.
\:\X317:Print two lines using the tricky pseudoprinted information\X
\U section~312.
\:\X314:Print type of token list\X
\U section~312.
\:\X353:Process an active-character control sequence and set $\\{state}\K\\{mid%
\_line}$\X
\U section~344.
\:\X727:Process node-or-noad \|q as much as possible in preparation for the
second pass of \\{mlist\_to\_hlist}, then move to the next item in the mlist\X
\U section~726.
\:\X1364:Process whatsit \|p in \\{vert\_break} loop, \&{goto} \\{not\_found}\X
\U section~973.
\:\X1121:Prune the current list, if necessary, until it contains only \\{char%
\_node}, \\{kern\_node}, \\{hlist\_node}, \\{vlist\_node}, \\{rule\_node}, and %
\\{ligature\_node} items; set \|n to the length of the list, and set \|q to the
list's tail\X
\U section~1119.
\:\X879:Prune unwanted nodes at the beginning of the next line\X
\U section~877.
\:\X318:Pseudoprint the line\X
\U section~312.
\:\X319:Pseudoprint the token list\X
\U section~312.
\:\X495:Push the condition stack\X
\U section~498.
\:\X226, 230, 238, 248, 265\*, 334, 376, 384, 411, 416, 468, 487, 491, 553,
780, 983, 1052, 1058, 1071, 1088, 1107, 1114, 1141, 1156, 1169, 1178, 1188,
1208, 1219, 1222, 1230, 1250, 1254, 1262, 1272, 1277, 1286, 1291, 1344:Put each
of \TeX's primitives into the hash table\X
\U section~1336.
\:\X90:Put help message on the transcript file\X
\U section~82.
\:\X1259:Put the (positive) `at' size into \|s\X
\U section~1258.
\:\X916:Put the \(c)characters $\\{hu}[\|i+1\to\,]$ into $\\{post\_break}(%
\|r)$, appending to this list and to \\{major\_tail} until synchronization has
been achieved\X
\U section~914.
\:\X915:Put the \(c)characters $\\{hu}[\|l+1\to\|i]$ and a hyphen into $\\{pre%
\_break}(\|r)$\X
\U section~914.
\:\X748:Put the \(f)fraction into a box with its delimiters, and make $\\{new%
\_hlist}(\|q)$ point to it\X
\U section~743.
\:\X887:Put the \(l)\.{\\leftskip} glue at the left and detach this line\X
\U section~880.
\:\X1014:Put the \(o)optimal current page into box 255, update \\{first\_mark}
and \\{bot\_mark}, append insertions to their boxes, and put the remaining
nodes back on the contribution list\X
\U section~1012.
\:\X886:Put the \(r)\.{\\rightskip} glue after node \|q\X
\U section~881.
\:\X562:Read and check the font data; \\{abort} if the \.{TFM} file is
malformed; if there's no room for this font, say so and \&{goto} \\{done};
otherwise $\\{incr}(\\{font\_ptr})$ and \&{goto} \\{done}\X
\U section~560.
\:\X571:Read box dimensions\X
\U section~562.
\:\X569:Read character data\X
\U section~562.
\:\X574:Read extensible character recipes\X
\U section~562.
\:\X575:Read font parameters\X
\U section~562.
\:\X573:Read ligature/kern program\X
\U section~562.
\:\X362:Read next line of file into \\{buffer}, or \&{goto} \\{restart} if the
file has ended\X
\U section~360.
\:\X52:Read one string, but return \\{false} if the string memory space is
getting too tight for comfort\X
\U section~51.
\:\X538\*:Read the first line of the new file\X
\U section~537.
\:\X51:Read the other strings from the \.{TEX.POOL} file and return \\{true},
or give an error message and return \\{false}\X
\U section~47.
\:\X568:Read the {\.{TFM}} header\X
\U section~562.
\:\X565:Read the {\.{TFM}} size fields\X
\U section~562.
\:\X1087:Readjust the height and depth of \\{cur\_box}, for \.{\\vtop}\X
\U section~1086.
\:\X913:Reconstitute nodes for the hyphenated word, inserting discretionary
hyphens\X
\U section~903.
\:\X855:Record a new feasible break\X
\U section~851.
\:\X1027:Recover from an unbalanced output routine\X
\U section~1026.
\:\X1372:Recover from an unbalanced write command\X
\U section~1371.
\:\X999:Recycle node \|p\X
\U section~997.
\:\X1081:Remove the last box, unless it's part of a discretionary\X
\U section~1080.
\:\X903:Replace nodes $\\{ha}\to\\{hb}$ by a sequence of nodes that includes
the discretionary hyphens\X
\U section~895.
\:\X1187:Replace the tail of the list by \|p\X
\U section~1186.
\:\X572:Replace \|z by $\|z↑\prime$ and compute $\alpha,\beta$\X
\U section~571.
\:\X396:Report a runaway argument and abort\X
\U sections~392 and~399.
\:\X667:Report a tight hbox and \&{goto} \\{common\_ending}, if this box is
sufficiently bad\X
\U section~664.
\:\X678:Report a tight vbox and \&{goto} \\{common\_ending}, if this box is
sufficiently bad\X
\U section~676.
\:\X395:Report an extra right brace and \&{goto} \\{continue}\X
\U section~392.
\:\X398:Report an improper use of the macro and abort\X
\U section~397.
\:\X666:Report an overfull hbox and \&{goto} \\{common\_ending}, if this box is
sufficiently bad\X
\U section~664.
\:\X677:Report an overfull vbox and \&{goto} \\{common\_ending}, if this box is
sufficiently bad\X
\U section~676.
\:\X660:Report an underfull hbox and \&{goto} \\{common\_ending}, if this box
is sufficiently bad\X
\U section~658.
\:\X674:Report an underfull vbox and \&{goto} \\{common\_ending}, if this box
is sufficiently bad\X
\U section~673.
\:\X1161:Report that an invalid delimiter code is being changed to null; set~$%
\\{cur\_val}\K0$\X
\U section~1160.
\:\X561:Report that the font won't be loaded\X
\U section~560.
\:\X460:Report that this dimension is out of range\X
\U section~448\*.
\:\X1026:Resume the page builder after an output routine has come to an end\X
\U section~1100.
\:\X878:Reverse the links of the relevant passive nodes, setting \\{cur\_p} to
the first breakpoint\X
\U section~877.
\:\X354:Scan a control sequence and set $\\{state}\K\\{skip\_blanks}$ or \\{mid%
\_line}\X
\U section~344.
\:\X444:Scan a numeric constant\X
\U section~440\*.
\:\X392:Scan a parameter until its delimiter string has been found; or, if $%
\|s=\\{null}$, simply scan the delimiter string\X
\U section~391.
\:\X1153:Scan a subformula enclosed in braces and \&{return}\X
\U section~1151.
\:\X356:Scan ahead in the buffer until finding a nonletter; if an expanded
control code is encountered, reduce it and \&{goto} \\{start\_cs}; otherwise if
a multiletter control sequence is found, adjust \\{cur\_cs} and \\{loc}, and %
\&{goto} \\{found}\X
\U section~354.
\:\X442:Scan an alphabetic character code into \\{cur\_val}\X
\U section~440\*.
\:\X443:Scan an optional space\X
\U sections~442, 448\*, 455, and~1200.
\:\X477:Scan and build the body of the token list; \&{goto} \\{found} when
finished\X
\U section~473.
\:\X474:Scan and build the parameter part of the macro definition\X
\U section~473.
\:\X452:Scan decimal fraction\X
\U section~448\*.
\:\X531:Scan file name in the buffer\X
\U section~530\*.
\:\X458:Scan for \(a)all other units and adjust \\{cur\_val} and \|f
accordingly; \&{goto} \\{done} in the case of scaled points\X
\U section~453.
\:\X454:Scan for \(f)\.{fil} units; \&{goto} \\{attach\_fraction} if found\X
\U section~453.
\:\X456:Scan for \(m)\.{mu} units and \&{goto} \\{attach\_fraction}\X
\U section~453.
\:\X455:Scan for \(u)units that are internal dimensions; \&{goto} \\{attach%
\_sign} with \\{cur\_val} set if found\X
\U section~453.
\:\X779:Scan preamble text until \\{cur\_cmd} is \\{tab\_mark} or \\{car\_ret},
looking for changes in the tabskip glue; append an alignrecord to the preamble
list\X
\U section~777.
\:\X471:Scan the argument for command \|c\X
\U section~470.
\:\X1258:Scan the font size specification\X
\U section~1257.
\:\X391:Scan the parameters and make $\\{link}(\|r)$ point to the macro body;
but \&{return} if an illegal \.{\\par} is detected\X
\U section~389.
\:\X777:Scan the preamble and record it in the \\{preamble} list\X
\U section~774.
\:\X783:Scan the template \<u_j>, putting the resulting token list in \\{hold%
\_head}\X
\U section~779.
\:\X784:Scan the template \<v_j>, putting the resulting token list in \\{hold%
\_head}\X
\U section~779.
\:\X453:Scan units and set \\{cur\_val} to $x\cdot(\\{cur\_val}+f/2↑{16})$,
where there are \|x units per sp; \&{goto} \\{attach\_sign} if the units are
internal\X
\U section~448\*.
\:\X255:Search \\{eqtb} for equivalents equal to \|p\X
\U section~172.
\:\X933:Search \\{hyph\_list} for pointers to \|p\X
\U section~172.
\:\X285:Search \\{save\_stack} for equivalents that point to \|p\X
\U section~172.
\:\X509:Select the appropriate case and \&{return} or \&{goto} \\{common%
\_ending}\X
\U section~501.
\:\X21, 23\*, 24, 74, 77, 80, 97, 166, 215, 254, 257, 272, 287, 383, 439, 481,
490, 521\*, 551, 556, 593, 596, 606, 648, 662, 685, 771, 928, 990, 1267, 1282,
1300, 1343, 1378\*, 1380\*:Set initial values of key variables\X
\U section~8\*.
\:\X849:Set line length parameters in preparation for hanging indentation\X
\U section~848.
\:\X805:Set the glue in all the unset boxes of the current list\X
\U section~800.
\:\X808:Set the glue in node \|r and change it from an unset node\X
\U section~807.
\:\X807:Set the unset box \|q and the unset boxes in it\X
\U section~805.
\:\X853:Set the value of \|b to the badness for shrinking the line, and compute
the corresponding \\{fit\_class}\X
\U section~851.
\:\X852:Set the value of \|b to the badness for stretching the line, and
compute the corresponding \\{fit\_class}\X
\U section~851.
\:\X1013:Set the value of \\{output\_penalty}\X
\U section~1012.
\:\X703:Set up the values of \\{cur\_size} and \\{cur\_mu}, based on \\{cur%
\_style}\X
\U sections~720, 726, 730, 754, 760, and~763.
\:\X243:Set variable \|c to the current escape character\X
\U section~63.
\:\X640:Ship box \|p out\X
\U section~638.
\:\X223:Show equivalent \|n, in region 1 or 2\X
\U section~252.
\:\X229:Show equivalent \|n, in region 3\X
\U section~252.
\:\X233:Show equivalent \|n, in region 4\X
\U section~252.
\:\X242:Show equivalent \|n, in region 5\X
\U section~252.
\:\X251:Show equivalent \|n, in region 6\X
\U section~252.
\:\X219:Show the auxiliary field, \|a\X
\U section~218.
\:\X1296:Show the current contents of a box\X
\U section~1293.
\:\X1294:Show the current meaning of a token, then \&{goto} \\{common\_ending}\X
\U section~1293.
\:\X1297:Show the current value of some parameter or register, then \&{goto} %
\\{common\_ending}\X
\U section~1293.
\:\X234:Show the font identifier in $\\{eqtb}[\|n]$\X
\U section~233.
\:\X235:Show the halfword code in $\\{eqtb}[\|n]$\X
\U section~233.
\:\X986:Show the status of the current page\X
\U section~218.
\:\X401:Show the text of the macro being expanded\X
\U section~389.
\:\X721:Simplify a trivial box\X
\U section~720.
\:\X500:Skip to \.{\\else} or \.{\\fi}, then \&{goto} \\{common\_ending}\X
\U section~498.
\:\X896\*:Skip to node \\{ha}, or \&{goto} \\{done1} if no hyphenation should
be attempted\X
\U section~894.
\:\X897:Skip to node \\{hb}, putting letters into \\{hu} and \\{hc}\X
\U section~894.
\:\X132:Sort \|p into the list starting at \\{rover} and advance \|p to $%
\\{rlink}(\|p)$\X
\U section~131.
\:\X1082:Split off part of a vertical box, make \\{cur\_box} point to it\X
\U section~1079.
\:\X1201:Squeeze the equation as much as possible; if there is an equation
number that should go on a separate line by itself, set~$\|e\K0$\X
\U section~1199.
\:\X991:Start a new current page\X
\U sections~215 and~1017.
\:\X1077:Store \(c)\\{cur\_box} in a box register\X
\U section~1075.
\:\X924:Store \(m)maximum values in the \\{hyf} table\X
\U section~923.
\:\X283:Store \(s)$\\{save\_stack}[\\{save\_ptr}]$ in $\\{eqtb}[\|p]$, unless $%
\\{eqtb}[\|p]$ holds a global value\X
\U section~282.
\:\X393:Store the current token, but \&{goto} \\{continue} if it is a blank
space that would become an undelimited parameter\X
\U section~392.
\:\X838:Subtract glue from \\{break\_width}\X
\U section~837.
\:\X841\*:Subtract the width of node \|v from \\{break\_width}\X
\U section~840.
\:\X369:Suppress expansion of the next token\X
\U section~367.
\:\X742:Swap the subscript and superscript into box \|x\X
\U section~738.
\:\X740:Switch to a larger accent if available and appropriate\X
\U section~738.
\:\X338:Tell the user what has run away and try to recover\X
\U section~336\*.
\:\X510:Terminate the current conditional and skip to \.{\\fi}\X
\U section~367.
\:\X505:Test box register status\X
\U section~501.
\:\X504:Test if an integer is odd\X
\U section~501.
\:\X506:Test if two characters match\X
\U section~501.
\:\X508:Test if two macro texts match\X
\U section~507.
\:\X507:Test if two tokens match\X
\U section~501.
\:\X503:Test relation between integers or dimensions\X
\U section~501.
\:\X558:The em width for \\{cur\_font}\X
\U section~455.
\:\X559:The x-height for \\{cur\_font}\X
\U section~455.
\:\X400:Tidy up the parameter just scanned, and tuck it away\X
\U section~392.
\:\X655:Transfer node \|p to the adjustment list\X
\U section~651.
\:\X884:Transplant the post-break list\X
\U section~882.
\:\X885:Transplant the pre-break list\X
\U section~882.
\:\X1152:Treat \\{cur\_chr} as an active character\X
\U sections~1151 and~1155.
\:\X873:Try the final line break at the end of the paragraph, and \&{goto} %
\\{done} if the desired breakpoints have been found\X
\U section~863.
\:\X127:Try to allocate within node \|p and its physical successors, and %
\&{goto} \\{found} if allocation was possible\X
\U section~125.
\:\X870:Try to break after a discretionary fragment\X
\U section~866.
\:\X535:Try to get a different log file name\X
\U section~534.
\:\X894:Try to hyphenate the following word\X
\U section~866.
\:\X1192:Try to recover from mismatched \.{\\right}\X
\U section~1191.
\:\X18, 25, 38, 101, 109, 113, 150, 212, 269, 300, 548, 594\*, 920, 925:Types
in the outer block\X
\U section~4.
\:\X1327:Undump a couple more things and the closing check word\X
\U section~1303.
\:\X1308:Undump constants for consistency check\X
\U section~1303.
\:\X1317:Undump regions 1 to 6 of \\{eqtb}\X
\U section~1314.
\:\X1323:Undump the array info for internal font number \|k\X
\U section~1321.
\:\X1312:Undump the dynamic memory\X
\U section~1303.
\:\X1321:Undump the font information\X
\U section~1303.
\:\X1319:Undump the hash table\X
\U section~1314.
\:\X1325:Undump the hyphenation tables\X
\U section~1303.
\:\X1310:Undump the string pool\X
\U section~1303.
\:\X1314:Undump the table of equivalents\X
\U section~1303.
\:\X869:Update the active widths by including the glue in $\\{glue\_ptr}(\\{cur%
\_p})$\X
\U section~866.
\:\X861:Update the active widths, since the first active node has been deleted\X
\U section~860.
\:\X976:Update the current height and depth measurements with respect to a glue
or kern node~\|p\X
\U section~972.
\:\X1004:Update the current page measurements with respect to the glue or kern
specified by node~\|p\X
\U section~997.
\:\X858:Update the value of \\{printed\_node} for symbolic displays\X
\U section~829.
\:\X1016:Update the values of \\{first\_mark} and \\{bot\_mark}\X
\U section~1014.
\:\X996:Update the values of \\{last\_glue}, \\{last\_penalty}, and \\{last%
\_kern}\X
\U section~994.
\:\X641:Update the values of \\{max\_h} and \\{max\_v}; but if the page is too
large, \&{goto} \\{done}\X
\U section~640.
\:\X798:Update width entry for spanned columns\X
\U section~796.
\:\X1182:Use code \|c to distinguish between generalized fractions\X
\U section~1181.
\:\X973:Use node \|p to update the current height and depth measurements; if
this node is not a legal breakpoint, \&{goto} \\{not\_found} or \\{update%
\_heights}, otherwise set \\{pi} to the associated penalty at the break\X
\U section~972.
\:\X566:Use size fields to allocate font information\X
\U section~562.
\:\X1358:Wipe out the whatsit node \|p and \&{goto} \\{done}\X
\U section~202.
\:\X1021:Wrap up the box specified by node \|r, splitting node \|p if called
for; set $\\{wait}\K\\{true}$ if node \|p holds a remainder after splitting\X
\U section~1020.
\con